Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: learning perl chapter 4

by davido (Archbishop)
on Jan 03, 2013 at 04:46 UTC ( #1011394=note: print w/ replies, xml ) Need Help??


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


Comment on Re: learning perl chapter 4
Select or Download Code
Re^2: learning perl chapter 4
by singho (Novice) on Jan 03, 2013 at 06:19 UTC
    thanks a lot it worked well, this is so stupid of me, since the error itself was so much clearly stating that i am using an uninitialized value. Thanks once more, i will try to be more careful.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1011394]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2014-07-12 03:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (238 votes), past polls