You could check out
AnyData or
DBD::AnyData,
but at this point I don't know if it'll make your life easier or
not. You ought to be able to get the basics of splitting a field
and searching for a value. You are splitting the file ok I think,
except the last field still has a newline.
If you can describe your
problem better, then we can offer better help; otherwise we're
just guessing. If you only need to search repeatedly by one
unique field (assuming name is unique), and the data will fit in memory, then I'd use a hash array with that field
as the key, and let the value just be the line as is (you can save if needed if you store just a scalar and split as needed rather than storing an array). If you
need to search by other fields also, take a look at one of the AnyData modules.
Or maybe you just want to split into a hash:
my @fields = qw(name num1 num2);
open(IN, "<$mailer_data_location");
while (<IN>) {
chomp;
my %data;
my @data{@foo} = split /\|/, $_;
print $_ if $data{name} eq 'Bill';
# Save array of hashes
push @AoH, \%data;
# Or just save array of values
push @array, [ split /\|/, $_ ];
}
close(IN);
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.