Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: read a hash from a file

by Anonymous Monk
on Apr 16, 2013 at 06:46 UTC ( [id://1028821]=note: print w/replies, xml ) Need Help??


in reply to Re: read a hash from a file
in thread read a hash from a file

I'm using File::Slurp
#!/usr/bin/perl use strict; use warnings; use File::Slurp; use Data::Dumper; $file="config.txt"; my %record =map{ s/#.*//; s/^\s+//; s/\s+$//; m/(.*?)\s*=\s*(.*)/; } read_file($file); print Dumper (\%record);
The dump from my code is
$VAR1={ 'Name' =>John Smith', 'URL' => '15', 'RANK' => 'Tier 1', 'URL' => 'http://somesite.com' };
but when the data is in the code, the dump is
$VAR1= bless( { 'Name' =>John Smith', 'URL' => '15', 'RANK' => 'Tier 1', 'URL' => 'http://somesite.com' }, 'REC' );

Replies are listed 'Best First'.
Re^3: read a hash from a file
by hdb (Monsignor) on Apr 16, 2013 at 06:51 UTC

    You are also having REC->new which must be provided by some module. Which one is that?

      opps. Thanks for pointing that out. The code pulls is a few custom libs written by my predecessor that I did't think were needed for this issue. Looks like they were.
      sub new { my ($self, %args) = @_; my @required = qw(NAME AGE RANK URL); my %cfg = map {uc $_ => $args{$_}} keys %args; for my $req (qw(NAME AGE RANK URL)) { croak "Required argument $req not found" unless exists $cfg{$req}; } return bless \%cfg, $self; }

        I cannot directly use this but what happens if you add the following to my code above:

        my $record = REC->new( %data ); print Dumper( $record );

Log In?
Username:
Password:

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

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

    No recent polls found