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

Re: Use with variable

by radiantmatrix (Parson)
on Sep 08, 2004 at 14:36 UTC ( [id://389378]=note: print w/replies, xml ) Need Help??


in reply to Use with variable

Others have answered (the eval route is the way I'd go); but I have a question. Was your query merely curiosity, or have you actually found a use for this technique?

I've never encountered a problem where this was the solution, and I'm just curious from a "hey, that's really unusual" point-of-view. Would you mind sharing more about what you're doing?

--
$me = rand($hacker{perl});

Replies are listed 'Best First'.
Re^2: Use with variable
by edan (Curate) on Sep 08, 2004 at 15:09 UTC

    It's easy to think of applications for this technique. Any sort of "plug-in" or "load-on-request" situation. Or "drivers", for instance. Ever use DBI? Notice how you only have to "use DBI;" and then the appropriate "DBD::*" module is loaded according to the datasource in your DBI->connect() call? That magic is done by dynamically loading a module that is contained in, yes, you guessed it, a variable! Actually, the eval method is used there:

    # --- load the code my $driver_class = "DBD::$driver"; eval qq{package # hide from PAUSE DBI::_firesafe; # just in case require $driver_class; # load the driver }; if ($@) { #....
    --
    edan

      Hey, neat. I've never written anything that could benefit from plugins, so I never encountered the need for that before.

      I definitely need to file that one away for later. Thanks!

      --
      $me = rand($hacker{perl});

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-25 05:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found