Just a simple [cpan.org] guy, hacking Perl for fun and profit since way back in the last millenium. You may find me hanging around in the monestary [perlmonks.org].
What am I working on right now? Probably the Sprog project [sourceforge.net].
GnuPG key Fingerprint:
6CA8 2022 5006 70E9 2D66
AE3F 1AF1 A20A 4CC0 0851
I just 'tidied up' some code from the form in sub_a (below) to the form in sub_b
my $sub = shift or die "must specify 'A' or 'B'\n";
if(uc($sub) eq 'A') {
sub_a();
}
else {
sub_b();
}
exit;
sub sub_a {
my $hashref = hashref();
while(my($k, $v) = each %{ $hashref }) {
print "$k => $v\n";
}
}
sub sub_b {
while(my($k, $v) = each %{ hashref() }) {
print "$k => $v\n";
}
}
sub hashref {
return { a => 1, b => 2, c => 3 };
}
I was surprised when my modified routine behaved in a different way to the original. When I thought about it, I realised what was going on and slapped myself. It's probably obvious to everyone else though.
Re: (Score:1)