Created
August 12, 2016 15:36
-
-
Save adkinss/3762edee5eb6ef3a4e80241259ac49fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
### | |
## This demonstrates how you can include BEGIN and END blocks in | |
## a perl script, but they don't necessarily execute in the order | |
## that they appear in the script. Here is the output when run: | |
## | |
## $ ./begin_end_perl_test.pl | |
## BEGIN MAIN | |
## BEGIN FOREACH | |
## BEGIN SUB | |
## inside MAIN | |
## a | |
## b | |
## c | |
## END SUB | |
## END FOREACH | |
## END MAIN | |
### | |
BEGIN { print "BEGIN MAIN\n" } | |
print "inside MAIN\n"; | |
END { print "END MAIN\n" } | |
foreach ( qw (a b c) ) { | |
BEGIN { print "BEGIN FOREACH\n" } | |
print "$_\n"; | |
END { print "END FOREACH\n" } | |
} | |
exit 0; | |
sub hello { | |
BEGIN { print "BEGIN SUB\n" } | |
print "inside SUB\n"; | |
END { print "END SUB\n" } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment