in reply to A curious case of of my()
This givessub foo{ my $var = shift; my $href = shift; my @array = $href->{pass_in} if defined $href and exists $href +->{pass_in}; push @array, $var; print "contents : @array\n"; } foo(1); foo(2);
However, commenting out the unused href code and declaring array as a lexical like:
givessub foo{ my $var = shift; my @array; #my $href = shift; #my @array = $href->{pass_in} if defined $href and exists $hre +f->{pass_in}; push @array, $var; print "contents : @array\n"; } foo(1); foo(2);
contents : 1
contents : 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A curious case of of my()
by shmem (Chancellor) on May 05, 2011 at 10:34 UTC |