Perl offers several different ways to include code from one file into another. Here are the deltas between the various inclusion constructs: 1) do $file is like eval `cat $file`, except the former: 1.1: searches @INC and updates %INC. 1.2:Continue reading… Difference between require and use ?
Category: Perl
Some Nice Perl Tips
Alias of perl builtin variables ========================================================== use English The English module provides aliases for the Perl builtin variables. $ARG is equivalent to $_ $1 equivalent to $MATCH $` equivalent to $PREMATCH $’ equivalent to $POSTMATCH Locate the source path ofContinue reading… Some Nice Perl Tips
Evaluation sequency of print statement
#!/usr/bin/perl print “Hey! “, mysub(“foo”); sub mysub { my $a=shift; print “$a “; } It outputs: foo Hey! 1 Because print evaluates its rightmost terms first, the “mysub()” is called before the “Hey! ” is printed. That prints “foo” andContinue reading… Evaluation sequency of print statement
Evaluation of if statements
#!/usr/bin/perl my ($x,$a)=(0,1); if ($a || $x++) { print “foon”; } print “$x”; At last, it will print 0 because, during the evaluation of if statement, since $a = 1, the next part of ‘or’ wont be evaluated. So $xContinue reading… Evaluation of if statements
$_ will hold the reference, not the copy of variable
#!/usr/bin/perl @list=qw(one two three); foreach(reverse @list) { print “$_n”; $_=”foo”; } print “$list[0]n”; Finally it will pring ‘foo’ not ‘one’. Because $_ isn’t a copy of the list element, it’s a reference. Modifying it will change the list.