Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: getting scalars out from txt file

by Roger (Parson)
on Oct 15, 2004 at 12:00 UTC ( [id://399482]=note: print w/replies, xml ) Need Help??


in reply to getting scalars out from txt file

How about something like this - build an array of hash references:
use IO::File; use Data::Dumper; my $f = new IO::File "file.txt", "r" or die "Can not open file"; my @vars; while (<$f>) { my ($d, $t) = $_ =~ /^(\d+)\|\|(\w+)$/; push @vars, { num => $d, txt => $t }; } print Dumper(\@vars);

The structure will be something like:
@vars = [ { num => '123', txt => 'abc' }, { num => '234', txt => 'frt' }, ... ];

To retrieve the variables:
$var[0]->{num}, $var[1]->{txt}, etc...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2024-04-25 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found