http://www.perlmonks.org?node_id=1011394


in reply to learning perl chapter 4

Move "my( $fred, $barney );" into the subroutine, and assign the parameter list to it, like this:

sub max { my( $fred, $barney ) = @_; print "You are using the subroutine max.\n"; #....etc...

The issue is that you're never unpacking any arguments inside of the sub, so $fred and $barney are never assigned a value. The other problem is that currently $fred and $barney are being declared at the wrong scope.

To avoid confusing behavior, your subroutine ought to also be returning a value explicitly, rather than relying on the behavior of returning the value of the last expression to be evaluated. It will work, but I never like seeing return values being created inside of an if/else block without explicitly using "return" as a visual cue of what's going on.


Dave