BEGIN …; in Perl [on hold]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I have a perl-script:



#!/usr/bin/perl 

BEGIN
print "That's BEGIN messagen";
BEGIN print "That's BEGIN-2 messagen"; ;
END print "That's END messagen"; ;
BEGIN print "That's BEGIN-3 messagen"; ;
;


It works so:



That's BEGIN-2 message
That's BEGIN-3 message
That's BEGIN message
That's END message


But why? It must prints in line 1 That's BEGIN message or no?










share|improve this question









New contributor




misdeed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Rui F Ribeiro, RalfFriedl, schily, John WH Smith, DarkHeart 2 days ago



  • This question does not appear to be about Unix or Linux within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.
















    up vote
    3
    down vote

    favorite












    I have a perl-script:



    #!/usr/bin/perl 

    BEGIN
    print "That's BEGIN messagen";
    BEGIN print "That's BEGIN-2 messagen"; ;
    END print "That's END messagen"; ;
    BEGIN print "That's BEGIN-3 messagen"; ;
    ;


    It works so:



    That's BEGIN-2 message
    That's BEGIN-3 message
    That's BEGIN message
    That's END message


    But why? It must prints in line 1 That's BEGIN message or no?










    share|improve this question









    New contributor




    misdeed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.











    put on hold as off-topic by Rui F Ribeiro, RalfFriedl, schily, John WH Smith, DarkHeart 2 days ago



    • This question does not appear to be about Unix or Linux within the scope defined in the help center.
    If this question can be reworded to fit the rules in the help center, please edit the question.














      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I have a perl-script:



      #!/usr/bin/perl 

      BEGIN
      print "That's BEGIN messagen";
      BEGIN print "That's BEGIN-2 messagen"; ;
      END print "That's END messagen"; ;
      BEGIN print "That's BEGIN-3 messagen"; ;
      ;


      It works so:



      That's BEGIN-2 message
      That's BEGIN-3 message
      That's BEGIN message
      That's END message


      But why? It must prints in line 1 That's BEGIN message or no?










      share|improve this question









      New contributor




      misdeed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I have a perl-script:



      #!/usr/bin/perl 

      BEGIN
      print "That's BEGIN messagen";
      BEGIN print "That's BEGIN-2 messagen"; ;
      END print "That's END messagen"; ;
      BEGIN print "That's BEGIN-3 messagen"; ;
      ;


      It works so:



      That's BEGIN-2 message
      That's BEGIN-3 message
      That's BEGIN message
      That's END message


      But why? It must prints in line 1 That's BEGIN message or no?







      perl






      share|improve this question









      New contributor




      misdeed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      misdeed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 2 days ago





















      New contributor




      misdeed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Sep 8 at 21:33









      misdeed

      1517




      1517




      New contributor




      misdeed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      misdeed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      misdeed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      put on hold as off-topic by Rui F Ribeiro, RalfFriedl, schily, John WH Smith, DarkHeart 2 days ago



      • This question does not appear to be about Unix or Linux within the scope defined in the help center.
      If this question can be reworded to fit the rules in the help center, please edit the question.




      put on hold as off-topic by Rui F Ribeiro, RalfFriedl, schily, John WH Smith, DarkHeart 2 days ago



      • This question does not appear to be about Unix or Linux within the scope defined in the help center.
      If this question can be reworded to fit the rules in the help center, please edit the question.




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          9
          down vote



          accepted










          The first BEGIN isn't run until it is completely defined (see documentation). That doesn't happen until the end of the last }.



          The others get run as they're completely defined — earlier.






          share|improve this answer



























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            9
            down vote



            accepted










            The first BEGIN isn't run until it is completely defined (see documentation). That doesn't happen until the end of the last }.



            The others get run as they're completely defined — earlier.






            share|improve this answer
























              up vote
              9
              down vote



              accepted










              The first BEGIN isn't run until it is completely defined (see documentation). That doesn't happen until the end of the last }.



              The others get run as they're completely defined — earlier.






              share|improve this answer






















                up vote
                9
                down vote



                accepted







                up vote
                9
                down vote



                accepted






                The first BEGIN isn't run until it is completely defined (see documentation). That doesn't happen until the end of the last }.



                The others get run as they're completely defined — earlier.






                share|improve this answer












                The first BEGIN isn't run until it is completely defined (see documentation). That doesn't happen until the end of the last }.



                The others get run as they're completely defined — earlier.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Sep 8 at 21:41









                Thomas Dickey

                49.9k586155




                49.9k586155












                    Comments

                    Popular posts from this blog

                    List of Gilmore Girls characters

                    What does second last employer means? [closed]

                    One-line joke