Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Returning multiple values from a subroutine

by McDarren (Abbot)
on Dec 28, 2012 at 11:56 UTC ( #1010696=note: print w/ replies, xml ) Need Help??


in reply to Returning multiple values from a subroutine

You are returning a reference to an array, which is a scalar value.
So you need to expect a scalar, and then de-reference it to get at the array values.

Observe:
#!/usr/bin/perl use strict; use warnings; my $currAcct = 1; my ( $subs, $SubId ) = getsubsFromAcct( $currAcct ); my $length = @$subs; print ("No of subs : $length and subs are @{$subs}"); sub getsubsFromAcct { my $acctNum = shift; my @subs = (); my $sbscrpId = 4; @subs = qw| 2 3 4 5 |; return ( \@subs, \$sbscrpId ); }
Prints:
No of subs : 4 and subs are 2 3 4 5

Hope this helps
Darren


Comment on Re: Returning multiple values from a subroutine
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2014-10-02 13:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (56 votes), past polls