Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
go ahead... be a heretic
 
PerlMonks  

Re: Perl record types

by naChoZ (Curate)
on Jan 17, 2008 at 14:28 UTC ( #662885=note: print w/ replies, xml ) Need Help??


in reply to Perl record types

Parse::CSV would really fit the bill, I even demonstrated using a pipe sep over here.

But if you're stuck without using modules, you could probably rig sub up to do what you want easily. This just reads a text file of values in the form of:

some_key_param=value

my $config = read_config({ filename => 'some_config_file' }); # {{{ read_config # sub read_config { my $args = shift; die "No configuration file specified\n" unless defined $args->{filename}; open my $conf_fh, '<', $args->{filename} or die "Error opening conf file...$!\n\n"; my $conf = {}; for (<$conf_fh>) { chomp; # use '=' as the separator if ( $_ =~ m/[=]/ ) { # skip these lines s/#.*//; s/^\s+//; s/\s+$//; next unless length $_; my ( $key, $value ) = split( /\s*=\s*/, $_, 2 ); $config->{$key} = $value; } } close $conf_fh; return $conf; } # }}}

--
naChoZ

Therapy is expensive. Popping bubble wrap is cheap. You choose.


Comment on Re: Perl record types
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2014-04-21 11:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (493 votes), past polls