Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Why no bareword warnings while inside of BEGIN

by muba (Priest)
on Mar 22, 2004 at 22:41 UTC ( #338804=note: print w/ replies, xml ) Need Help??


in reply to Why no bareword warnings while inside of BEGIN

update: nevermind

Just know that a BEGIN block is not marked by a sub keyword. You just use BEGIN {...}

Also, IIRC, the strict and warning pragma's are imported *after* the BEGIN block. But it's very good possible I'm wrong here.


Comment on Re: Why no bareword warnings while inside of BEGIN
Download Code
Re: Re: Why no bareword warnings while inside of BEGIN
by Juerd (Abbot) on Mar 22, 2004 at 22:44 UTC

    A BEGIN block is not marked by the sub keyword. Instead, you just use BEGIN {...}

    It can be, though. "sub BEGIN" doesn't create a normal sub called BEGIN, but it is valid syntax. In fact, it is how B::Deparse deparses BEGIN blocks. The same goes for CHECK, INIT and END. See also what perlmod has to say about this.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Re: Re: Why no bareword warnings while inside of BEGIN
by chromatic (Archbishop) on Mar 22, 2004 at 23:12 UTC
    Also, IIRC, the strict and warning pragma's are imported *after* the BEGIN block.

    There's one way to find out :)

    $ perl use strict; BEGIN { $x = 'y'; $$x = 1; print $y } Global symbol "$x" requires explicit package name at - line 2. Global symbol "$x" requires explicit package name at - line 2. Global symbol "$y" requires explicit package name at - line 2. BEGIN not safe after errors--compilation aborted at - line 2.

    As it turns out, use calls reduce to BEGIN blocks and BEGIN blocks fire in order of encountering.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://338804]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (12)
As of 2014-07-10 12:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (209 votes), past polls