G
Gregory Toomey
I've simplified a problem shown in the fragment below. I'm defining a hash
in terms of a function of one of its components.
I would have hoped to get
param 1 is carrie
as part of the output but dont.
This has left me confused about Perl evaluation. I dont think Perl handles
lazy evaluation, and gives me a result I did not expect.
Any comments on what I should be doing to get the semantics I want?
gtoomey
--------------
Fragment:
sub printhash {
my %h= (@_);
for (keys(%h)) {print "$_ = $h{$_}\n"}
}
sub myfunc {
print "param 1 is $_[0]\n";
return ('a'=>'b','c'=>'d')
}
my %hash;
%hash= (
"cat"=>'tony',
"dog"=>'carrie',
myfunc($hash{dog})
);
printhash(%hash);
----------------
Output:
param 1 is
cat = tony
c = d
a = b
dog = carrie
in terms of a function of one of its components.
I would have hoped to get
param 1 is carrie
as part of the output but dont.
This has left me confused about Perl evaluation. I dont think Perl handles
lazy evaluation, and gives me a result I did not expect.
Any comments on what I should be doing to get the semantics I want?
gtoomey
--------------
Fragment:
sub printhash {
my %h= (@_);
for (keys(%h)) {print "$_ = $h{$_}\n"}
}
sub myfunc {
print "param 1 is $_[0]\n";
return ('a'=>'b','c'=>'d')
}
my %hash;
%hash= (
"cat"=>'tony',
"dog"=>'carrie',
myfunc($hash{dog})
);
printhash(%hash);
----------------
Output:
param 1 is
cat = tony
c = d
a = b
dog = carrie