Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: More efficient return of values from sub

by fglock (Vicar)
on Mar 26, 2005 at 03:12 UTC ( #442448=note: print w/ replies, xml ) Need Help??


in reply to More efficient return of values from sub

sub routine_A { my ($name) = getinfo('name'); print $name; } sub routine_B { my ($address) = getinfo('address'); print $address; } sub getinfo { my %data; $data{name} = "Sam"; $data{address} = "123 Main St"; return @data{ @_ }; } routine_A; routine_B; print getinfo( 'name', 'address' );


Comment on Re: More efficient return of values from sub
Download Code
Replies are listed 'Best First'.
Re^2: More efficient return of values from sub
by bradcathey (Prior) on Mar 26, 2005 at 14:08 UTC

    Perfect fglock! I actually wondered about hashes for a fleeting second after posting, but this has helped me see the logic and application of this approach. It keeps it 1) simple, 2) no outside modules, and 3) no global variables (one of my early 'solutions').


    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2015-07-31 19:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (280 votes), past polls