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);