I wonder if you meant something different from the answers
Fletch and
imp gave you. Did you perhaps mean, "How can I populate a hash directly from a file of data like that in my OP?" Something like
%hash = {some magic here} <FILE>; rather than
while(<FILE>){ # do something # $hash{$key} = $value;}. If that was your question the answer is yes and the magic used would be the
map function.
use strict;
use warnings;
use Data::Dumper;
my %zipDB =
map { $_->[0], join q{|}, @{$_}[1 .. 3] }
map { chomp; [ unpack q{A5 A2 A3 A*}, $_ ] }
<DATA>;
print Data::Dumper->Dumpxs([\%zipDB], [qw{*zipDB}]);
__END__
00601PR787ADJUNTAS
00602PR787AGUADA
00603PR787AGUADILLA
00604PR787AGUADILLA
00605PR787AGUADILLA
00606PR787MARICAO
00610PR787ANASCO
00611PR787ANGELES
00612PR787ARECIBO
00613PR787ARECIBO
The output is
%zipDB = (
'00611' => 'PR|787|ANGELES',
'00612' => 'PR|787|ARECIBO',
'00603' => 'PR|787|AGUADILLA',
'00610' => 'PR|787|ANASCO',
'00606' => 'PR|787|MARICAO',
'00601' => 'PR|787|ADJUNTAS',
'00602' => 'PR|787|AGUADA',
'00605' => 'PR|787|AGUADILLA',
'00613' => 'PR|787|ARECIBO',
'00604' => 'PR|787|AGUADILLA'
);
If I have guessed wrong and this isn't what you meant then I hope the post was of interest anyway :)
Cheers,
JohnGG
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.