programming-examples/perl/Subroutine/BEGIN and END Subroutines (Startup and Finish).pl
2019-11-15 12:59:38 +01:00

11 lines
527 B
Perl

#A BEGIN subroutine is executed immediately, before the rest of the file is even parsed.
#If you have multiple BEGINs, they will be executed in the order they were defined.
#The END subroutine is executed when all is done.
#Multiple END blocks are executed in reverse order.
#The keyword sub is not necessary when using these special subroutines.
#!/bin/perl
chdir("/mydir") || die "Can't cd: $!\n";
BEGIN{ print "Welcome to my Program.\n"};
END{ print "Bailing out somewhere near line ",__ LINE__," So long.\n"};