K
K4 Monk
I don't understand references very well (even after reading some docs
on this). How can I get a mixed array of hash and array back from a
function? How do I send it such a list of mixed types? Can someone
please help!
#!/usr/bin/perl
use strict;
sub func {
my @list;
push (@list, "map");
push (@list, "key");
push (@list, "l");
push (@list, "j");
my @arr;
push (@arr, "egg");
push (@arr, "hell");
return ( \@list, \@arr );
}
sub func {
my $pid=shift;
my $p=shift;
my $ref=shift;
print "$ref\n";
my %funcs=%{\$ref};
foreach my $key(keys %funcs) { print "$key\n"; }
}
my @arrref = &func();
my @l = @{$arrref[0]};
my @r = @{$arrref[1]};
print "keys\n";
foreach my $k(@l) { print "$k\n"; }
print "array\n";
foreach my $rr(@r) { print "$rr\n"; }
my $pid=10;
my $p=11;
my %hash;
$hash{"derp"} = 10;
$hash{"herp"} = 11;
&func($pid, $p, \(%hash));
on this). How can I get a mixed array of hash and array back from a
function? How do I send it such a list of mixed types? Can someone
please help!
#!/usr/bin/perl
use strict;
sub func {
my @list;
push (@list, "map");
push (@list, "key");
push (@list, "l");
push (@list, "j");
my @arr;
push (@arr, "egg");
push (@arr, "hell");
return ( \@list, \@arr );
}
sub func {
my $pid=shift;
my $p=shift;
my $ref=shift;
print "$ref\n";
my %funcs=%{\$ref};
foreach my $key(keys %funcs) { print "$key\n"; }
}
my @arrref = &func();
my @l = @{$arrref[0]};
my @r = @{$arrref[1]};
print "keys\n";
foreach my $k(@l) { print "$k\n"; }
print "array\n";
foreach my $rr(@r) { print "$rr\n"; }
my $pid=10;
my $p=11;
my %hash;
$hash{"derp"} = 10;
$hash{"herp"} = 11;
&func($pid, $p, \(%hash));