I'm also not certain what you need, but here's what I pulled together from your description.
#!/usr/bin/perl
use strict;
use warnings;
# 2022-0108: Read a CSV line w/ three elements, building a hash using
# the third element and populated with the second element.
use Data::Dumper;
{
my %hash;
while (<DATA>) {
s/\s+$//;
my @w = split(/,/);
push ( @{ $hash{ $w[2] } }, $w[1] );
}
print Dumper ( \%hash );
}
__DATA__
702005010554291,5016554291,7020000023F22
702005010524898,5016524898,70200000441E0
702005010660208,5016660208,7020000033FD0
702005010509777,5016509777,7020000033FF0
702005010633781,5016633781,7020000024092
702005010616472,5016616472,7020000043FE2
310005010601516,5016601516,7020000044201
702005010526097,5016526097,7020000013EB1
702005010681238,5016681238,7020000044052
702005010551103,5016551103,7020000023F12
702005010625010,5016625010,7020000023F51
This produces the following results:
$VAR1 = {
'7020000023F51' => [
'5016625010'
],
'7020000044052' => [
'5016681238'
],
'7020000033FD0' => [
'5016660208'
],
'7020000044201' => [
'5016601516'
],
'7020000023F22' => [
'5016554291'
],
'7020000043FE2' => [
'5016616472'
],
'7020000024092' => [
'5016633781'
],
'7020000013EB1' => [
'5016526097'
],
'7020000023F12' => [
'5016551103'
],
'7020000033FF0' => [
'5016509777'
],
'70200000441E0' => [
'5016524898'
]
};
Let us know if this is what you wanted.
Alex / talexb / Toronto
Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.