Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^5: Returning and passing data to and from subroutines

by ssandv (Hermit)
on Jul 21, 2010 at 15:34 UTC ( [id://850670]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Returning and passing data to and from subroutines
in thread Returning and passing data to and from subroutines

Well, one problem you're having is context confusion:

perl -e 'sub foo {@a=(1,2,4);return @a}; $bar=foo(); print "bar is $bar\n";' bar is 3
If you want $option to get the _value_, instead of the number of elements in the array, you'll need to either learn about wantarray so your sub knows how it's called, or return a scalar, or do list assignment (which looks like ($option)=process_input($option). Perl is examining @data in a scalar context in your return statement, which gives the number of elements it contains, rather than its contents, because the sub was called as the rvalue of a scalar assignment.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-28 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found