I just realized even after years of dabbling in perl I don't
understand how function calls work. Can someone please be kind enough
to help me understand how to return multiple objects from a function
and use them? Here I'm interested in returning two objects: a hash,
and a list respectively. I'm sure there is more than one way of doing
this in perl

#!/usr/bin/perl
use strict;

sub func {
        my %list;
        $list{"map"} = "key";
        $list{"l"}="j";

        my @arr;
        push (@arr, "egg");
        push (@arr, "hell");


        return \(%list, @arr);

}

 my $arrref = &func();
 my %l = $arrref->[0];
 my @r = $arrref->[1];

 print "keys\n";
foreach my $k(keys %l) { print "$k\n"; }
print "array\n";
foreach my $rr(@r) { print "$rr\n"; }

This prints:

vidura@localhost/tmp $ ./v.pl
keys
egg
array
hell


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to