in reply to use strict and subroutines

This should solve your problem :
#!/usr/local/bin/perl use strict; $myname=myname(); print "my name is $myname\n"; sub myname { my $myname = "bill"; return $myname; }

Your problem is that you seem to not understand the scope of variable (the way my works)
and the way a sub return the value (you call a sub returning the value needed in a void context)
I would have (re)written it this way :
#!/usr/local/bin/perl use strict; my $name=myname(); print "my name is $name\n"; sub myname { my $myname = "bill"; return $myname; }

Now you should see that the var in the sub has nothing to do with the one outsite the sub
(it's a lexically scoped var, which doesn't exist anymore outside the scope of the sub)

"Only Bad Coders Badly Code In Perl" (OBC2IP)

Replies are listed 'Best First'.
Re: Re: use strict and subroutines
by YoungPups (Beadle) on Apr 02, 2001 at 20:27 UTC
    Actually, your first version wouldn't work under strict. The first occurrence of $myname has not yet been declared. Just a point of order... The second is a good example.