in reply to 'my' headache...why doesn't this work?

Deparse is your friend.

$ perl -MO=Deparse -e 'my $columnsum += $_->[$colnum] for @data;' foreach $_ (@data) { my $columnsum += $$_[$colnum]; }

The my declaration is within the for loop, so for each @data, a new $columnsum is created.

Update: As demerphq has pointed out, the deparse output is wrong for this snippet. The todo section at the top of B::Deparse even mentions this specifically. Now I'm off to search for what it is really doing...

Update2: A google search for "my $x if 0" returns some answers. There is even a node here in the monestary that talks about it.

Replies are listed 'Best First'.
Re: Re: 'my' headache... Dont Trust Deparse!
by demerphq (Chancellor) on Apr 05, 2002 at 17:48 UTC
    Deparse is wrong.

    See my earlier comments to this thread.

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.