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

Re: Re: No excuses about not using CGI.pm

by merlyn (Sage)
on May 03, 2001 at 19:49 UTC ( #77684=note: print w/ replies, xml ) Need Help??


in reply to Re: No excuses about not using CGI.pm
in thread variables not posting?

Not quite. The import can import prototypes, which need to sucked in before the rest of the code is compiled. Maybe not true for CGI.pm in particular, but I like to show a general template that can be copied for other problems without fear.

-- Randal L. Schwartz, Perl hacker


Comment on Re: Re: No excuses about not using CGI.pm
Re (tilly) 3: No excuses about not using CGI.pm
by tilly (Archbishop) on May 04, 2001 at 00:25 UTC
    Actually in general I consider avoiding unexpected prototype conversion a good thing. In which case having a good way to silently ignore unwanted prototypes (and trust me, I rarely want them) is a good thing!
      But it's not silent (under -w):
      mysub(1); BEGIN { package Foo; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(mysub); sub mysub ($) { print "mysub: @_\n" }; } BEGIN { Foo->import(); } ## Output main::mysub() called too early to check prototype at C:\Projects\GPerl +\Test\g1.pl line 1. mysub: 1
      Though I don't quite understand, if BEGIN blocks are executed before the rest of the containing file is parsed (so sayeth perlmod), why does this happen at all?
         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print
        You got it in the wrong order. You can't execute a BEGIN block before you compile it, and you compile it in the order in the file. So you've compiled the lone mysub at the top, then you compile the first BEGIN block, then execute it, then compile the second BEGIN block, then execute it and OOPS! there's the problem.

        Put the lone mysub at the bottom of the file, and it'll be all good.

        -- Randal L. Schwartz, Perl hacker

        It is silent for me in 5.005_03.

        But try the following:

        mysub(1); BEGIN { package Foo; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(mysub); sub mysub ($) { print "mysub: @_\n" }; } BEGIN { warn("About to import\n"); Foo->import(); warn("Imported\n"); }
        I suspect that the warning comes when it imports and realizes that it has already parsed code whose meaning is being changed by the prototype. And the way I said that should go a long way to answering your question.

        BEGIN blocks are executed once the BEGIN block is parsed. That means that they run before later code is parsed, and after prior code is already parsed. This is also why BEGIN blocks run in the order they appear in the file...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2014-08-01 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls