Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: using strict and a config file

by guha (Priest)
on Nov 12, 2001 at 16:12 UTC ( [id://124809]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: using strict and a config file
in thread using strict and a config file

How about this setup which I think is clean way to do it.

Content of the config file, say cfg.cfg

%cfg = (To => 'to', From => 'from', Subject => 'subject', Message => "message\nmsg2\n", Page_Title => 'MailTo'); %cfg;

Then you do something like this in the main program.

use strict; . . my $file = 'cfg.cfg'; my %cfg; my $return = do $file; unless ($return) { die "couldn't parse $file: $@" if $@; die "couldn't do $file: $!" unless defined $return; die "couldn't run $file" unless $return; } %cfg = %{$return};

And then later in your code use it as

<td><select name="$cfg{From}" size="1"> more code... </select></td> </tr> <tr> <td>Subject:</td> <td><input type="text" name="$cfg{Subject}" size="24"> +</t
This is easily expanded to have several different configs in the same file.
Ex $cfg{Guest}{To}, $cfg{Admin}{Page_Title}, etc etc

Log In?
Username:
Password:

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

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

    No recent polls found