Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Returning values from a sub routine.

by Anonymous Monk
on Jul 31, 2012 at 17:05 UTC ( #984627=note: print w/ replies, xml ) Need Help??


in reply to Re: Returning values from a sub routine.
in thread Returning values from a sub routine.

Would you be able to post some sample code using the code posted here using an anonymous array to return the values?


Comment on Re^2: Returning values from a sub routine.
Re^3: Returning values from a sub routine.
by suaveant (Parson) on Jul 31, 2012 at 17:33 UTC
    I can get you started.

    You wouldn't be able to assign directly to a hash slice like you do, you'd have to iterate. If using a hash of arrays I'd always use an array as the value, even if its only one value, will help keep the code simpler. You can loop through both arrays separately or combine them

    for my $name ( @names_combined ) { push @{$emails{$name}}, shift(@emails_combined); }

                    - Ant
                    - Some of my best work - (1 2 3)

      Sorry it didnt help, where in this sample code would your code go?
        sub test { my (@names_all, @email_all); my @names = qw(Joe mary ann pete amy jerry Joe ann John John ); my @email = qw(joe@test.com mary@test.com ann@nowhere.com pete@here.com amy@ok.com jerry@b.com joe@test.com ann@nowhere. +com John@test.com John@ok.com); my %emails; my @names_combined = (@names,@names_all); my @emails_combined = (@email,@email_all); for my $name ( @names_combined ) { push @{$emails{$name}}, shift(@emails_combined); } return \%emails; }
        Not tested, but should get you going in the right direction. Maybe read some Perl tutorials or Learning Perl to get a better overall feel for the language.

                        - Ant
                        - Some of my best work - (1 2 3)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-10-25 21:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (149 votes), past polls