develooper Front page | perl.perl5.porters | Postings from December 2010

Warn on my $i = .... if .... ?

Thread Next
From:
Karen Etheridge
Date:
December 7, 2010 11:32
Subject:
Warn on my $i = .... if .... ?
Message ID:
20101207193213.GA96561@tequila.etheridge.ca

I was recently bitten by this "unexpected" behaviour:

    sub inc {
        my $static if 0;
        print $static++;
    }
    inc; inc; inc; inc;

(This prints 0123, instead of the 0000 you would get when the 'if 0' is
removed.)

...and I found this rather old thread in the p5p archives, which not only
discusses whether this violates the "principle of least surprise" but steps
through some of the gory details:
http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2000-05/msg00686.html

One of the outcomes was a suggestion (by Barrie Slaymaker) to produce a
warning when such code was encountered. This didn't seem to ever happen, so
I wanted to find out what the current opinions are on adding this warning?


- Karen Etheridge, karen@etheridge.ca

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About