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” and returns a value of “1”. The “Hey !” is evaluated and printed, and then the “1” that “mysub()” returned.

Leave a Reply

Your email address will not be published. Required fields are marked *