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

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

Thread Next
Karen Etheridge
December 7, 2010 11:32
Warn on my $i = .... if .... ?
Message ID:

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

...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:

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,

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About