Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Never, never, never

by theorbtwo (Prior)
on Apr 22, 2005 at 19:17 UTC ( [id://450543]=note: print w/replies, xml ) Need Help??


in reply to Never, never, never

johnnywang, there's an old saying, quoted in somebody's .signature, to the effect of "examine what is being said, not who is speaking".

Additionally, never say never again.

Exporter uses symbolic references in order to allow you to specify the names of subs you wish to import and export. You pretty well have to use them there, and in AUTOLOAD subs that create new subroutines at runtime.

You can use $1 without checking that you match first if you really do want the strange scoping behavior -- that is, that you want the $1 from the most recently succeeded match.

Of course, I wouldn't do either of those things without comments, but that doesn't mean that they aren't occassionally useful things to do.


Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

Replies are listed 'Best First'.
Re^2: Never, never, never
by Joost (Canon) on Apr 22, 2005 at 20:00 UTC
    I agree.

    In my experience, symbolic references should be used (when you can) in preference to eval STRING - basically, when you're generating code (esp. converting closures to "regular" subroutines etc.) In those cases they're generally easier to use and less error prone than eval "".

    Eval string is still useful too - but you need to be wary of scoping issues and typo's, which can be difficult in generated code. The only thing I regulary use it for is eval "use $some_module";

Re^2: Never, never, never
by Roy Johnson (Monsignor) on Apr 22, 2005 at 22:27 UTC
    Actually, you can hit the symbol table directly, so you never need to use symbolic references per se. Of course, as long as you're aware that you're going into the symbol table, and it's the Right Thing To Do, there's no reason not to use the sym refs.

    Caution: Contents may have been coded under pressure.

      Eh, there's a moral equivlency there. $Package::{'bar'} is a symref just as much as ${'$bar'}, even if one violates use strict 'refs'; and the other does not, I'd say. (But I think there's a good argument the other direction as well.)


      Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

Re^2: Never, never, never
by doom (Deacon) on Apr 25, 2005 at 13:53 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-03-28 08:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found