Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Avoiding hard-coding

by mirod (Canon)
on Nov 14, 2003 at 23:38 UTC ( [id://307252]=note: print w/replies, xml ) Need Help??


in reply to Avoiding hard-coding

I use a default location (using FindBin if the default location is the code directory) and a command line argument to change it if needed:

use YAML qw(LoadFile); # my config files are often in YAML use FindBin qw($Bin); # $Bin gives the code directory use Getopt::Std; # Getopt::Long is probably better my %opt; getopts( 'c:' => \%opt); # -c <config_file> $opt{c} ||= "$Bin/config.yaml"; # default location # this is far from perfect, I should really open the file properly, # slurp it and then use YAML to parse the content # as it is, if the file exists but cannot be opened the # error message is a bit ugly... die "cannot find file config file $opt{c}" unless( -f $opt{c}); my $env= LoadFile( $opt{c});

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-25 23:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found