Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re: Parse file and creating hashes by talexb
in thread Parse file and creating hashes by PerlMonger79

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-20 04:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found