############################################################################################################
#Author: Leo
#Email: ahyeek@gmail.com
#Desc:
# The author has created some codes to test out during the learning process for the book called
# <Professional Perl Programming>, publisher: Wrox Pree Ltd, year in 2001
# ISBN: 1-861004-49-4.
#
#Summary:
# Examples code for <Professional Perl Programming>.
# Chapter 6: Structure, Flow, and Control
#
############################################################################################################
use warnings;
#A bare block using definition
{
#define six scalars in new block scope:
my($sec, $min, $hour, $day, $month, $year) = localtime();
#variable exist and can be used inside the block.
print "The time is: $hour: $min. $sec\n";
print "Date before processed: $year / $month / $day \n";
$month++;
$year+=1900;
print "The date is: $year / $month / $day \n";
#End of block.
}
print "\$sec is not defined outside block.\n" unless defined($sec);
#While block.
print "Enter: ";
while(my $line = <>)
{
last if $line =~ /quit/;
print "You entered: $line";
print "Enter: ";
}
###########################################################################################
# Special Blocks
###########################################################################################
END {
print "Exiting... This was printed at the end although it was coded first.\n";
}
print "Running ...Printed during the program run sequentially.\n";
BEGIN{
print "Compiling ... This will be printed first because printed during program was compiled.\n";
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment