Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

grantm (164)

grantm
  (email not shown publicly)
http://www.mclean.net.nz/

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

Journal of grantm (164)

Thursday June 01, 2006
09:40 PM

Bitten!

[ #29783 ]

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.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.