Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Re: while(<>) { ... } considered harmful

by schwern (Scribe)
on Aug 07, 2003 at 21:40 UTC ( #282040=note: print w/ replies, xml ) Need Help??


in reply to Re: while(<>) { ... } considered harmful
in thread while(<>) { ... } considered harmful

require returns the last evaluated expression in the file. Normally this is 1, but I've seen people do wacky things like have "return %hash" as the last expression and do "%hash = require Foo::Bar";


Comment on Re: Re: while(<>) { ... } considered harmful
Replies are listed 'Best First'.
Re^3: while(<>) { ... } considered harmful (...= require ...)
by tye (Cardinal) on Aug 18, 2003 at 21:44 UTC
    require returns the last evaluated expression in the file

    Only the first time:

    > perl -de 0 ... DB<1> x require 'con' 'this is true'; ^Z 0 'this is true' DB<2> x require 'con' 0 1 DB<3> x require 'con' 0 1 DB<4>
    I've seen people do wacky things like have "return %hash" as the last expression and do "%hash = require Foo::Bar";

    So such code will break as soon as more than one use of the module is attempted from a single run. That's a bit of a shame too, since Perl could really use something along those lines.

                    - tye
Re: Re: Re: while(<>) { ... } considered harmful
by Juerd (Abbot) on Aug 07, 2003 at 21:48 UTC

    Since my post, I have used eval { require ... } ? ...->import : *symbol = sub { dummy here } a lot.

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

Log In?
Username:
Password:

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

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

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (280 votes), past polls