in reply to use strict and subroutines
A return token is really quite optional - Perl will return the last value evaluated, so:my $myname = myname(); # or print myname(), "\n";
will return 'bill.' As for your second example - $myname is declared outside of sub myname - but it is accessible by myname(). It works because you defined $myname, unlike you did in the first example.sub myname { my $name = "bill"; }
The best way to deal with this is like so:
my $myname = myname(); print "my name is $myname\n"; sub myname { my $name = "bill"; # notice subtle change in variable name return $name; # not necessary, $myname works too } # but it is not the same $myname ;)
Jeff
R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
L-L--L-L--L-L--L-L--L-L--L-L--L-L--
|
|---|