Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Sharing a variable between (>=) 2 files

by LighthouseJ (Sexton)
on Dec 03, 2007 at 21:20 UTC ( [id://654651]=note: print w/replies, xml ) Need Help??


in reply to Sharing a variable between (>=) 2 files

I changed the settings.pl to use regular key names instead of variables. If I want to interpret a file as perl code, I generally use an eval this way:
$ cat settings.pl %default_settings = ( verbose => 1, debug => 0, help => 0, game => "etqw" ); $ cat app.pl #!/usr/bin/perl -w my $settings_file = "./settings.pl"; use strict; my %default_settings = (); open SETTINGS,$settings_file or die "cannot open $settings_file"; my @data = <SETTINGS>; eval "@data"; close SETTINGS; my %settings = %default_settings; print $_,'->',$settings{$_},"\n" foreach (keys %settings); $ ./app.pl verbose->1 game->etqw debug->0 help->0
This allows me to not 'require' anything at startup but rather gives me the flexibility to do what I need if I need it.

"The three principal virtues of a programmer are Laziness, Impatience, and Hubris. See the Camel Book for why." -- `man perl`

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2025-03-25 21:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (67 votes). Check out past polls.

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.