Since your data file seems to be a text file (like a csv only with whitespace as separator) you could consider using
Text::CSV_XS:
#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV_XS;
use Data::Dumper;
my $param = { binary => 1,
auto_diag => 1,
sep_char => ' ',
eol => $/,
};
my %hash;
my $csv = Text::CSV_XS->new ( $param );
while ( my $row = $csv->getline( *DATA ) )
{
print "@$row[0,1]\n"; # or whatever.
$hash{$row->[0]} = $row->[1]; # read into a hash.
}
print Dumper \%hash;
__END__
b c a
a c d
d e b
Output of a Data::Dumper print statement is:
$VAR1 = {
'a' => 'c',
'b' => 'c',
'd' => 'e'
};
Update: Typo corrected.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.