Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: "use vars" vs. "our" or Strict after the fact

by epoptai (Curate)
on Mar 31, 2001 at 04:01 UTC ( [id://68572]=note: print w/replies, xml ) Need Help??


in reply to "use vars" vs. "our" or Strict after the fact

One quick and dirty way to do this is to declare some variables in the script, eval require the file, if eval succeeds equate the script var names with the var names in the required file.
use strict; use vars qw($filevar1 $filevar2 $filevar3); my($scriptvar1,$scriptvar2,$scriptvar3,$required) = 0; my$file = 'somefile'; if(-e $file){ if(eval "require '$file'"){ $scriptvar1 = $filevar1; $scriptvar2 = $filevar2; $scriptvar3 = $filevar3; $required = 1; } }
Those my variables can be included in the use vars statement instead (but not vice-versa).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-19 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found