develooper Front page | perl.perl5.porters | Postings from May 2008

Should potentially confusing labels emit a warning?

Thread Next
From:
Aristotle Pagaltzis
Date:
May 8, 2008 04:35
Subject:
Should potentially confusing labels emit a warning?
Message ID:
20080508113508.GE4173@klangraum.plasmasturm.org
Hi all,

Andy Lester just wrote about this:

* <http://perlbuzz.com/2008/05/colons-invalidate-your-begin-and-end-blocks.html>
> Credit Randy Lauen for bringing this to my attention.  Today at
> my day job he found a horrifying code construct, one that I'd
> been using (incorrectly) for quite some time now.  You see,
> these two blocks are not the same:
> 
>     BEGIN {
>         # Here's some code that gets executed at compile time
>     }
>     
>     BEGIN: {
>         # This code gets executed at run time, because the colon
>         # after BEGIN means it's just a plain old label
>     }
> 
> Randy had been tracking down a bug for over an hour and
> couldn't figure out why his variables weren't getting set at
> compile time.

A Perl::Critic policy has been submitted for this, but it seems
to me that this is a potential bug worthy of attention from the
core. Now, I am hesitant on adding new warnings but I think in
this case it really is worthwhile; it could, after all, be
disabled easily enough. (What was the consensus on making
`use warnings` mean something other than `use warnings 'all'`?)

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

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