Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
laziness, impatience, and hubris
 
PerlMonks  

Re^3: concatenation of lines from two different files

by agianni (Hermit)
on Aug 17, 2007 at 14:40 UTC ( #633314=note: print w/ replies, xml ) Need Help??


in reply to Re^2: concatenation of lines from two different files
in thread concatenation of lines from two different files

If that's the case, you'll need to make the hash storing the contents of the first file a hash of arrays (or, rather, a hash of arrayrefs) rather than a simple hash, so you can store each line that matches the id:

my %file1_row_for; while (my $input = <THAT_FILE>){ # only grab column 2 my ( undef, $id ) = split /;/, $input; # add this line to the array of data for this key push @{ $file1_row_for{$id} } = $input; }

Then when you want to output it at the end of the line you can:

print join ';', @{ $file_row_for{$id} } if scalar @{ $file_row_for{$id +} };

Note that you'll just want to check for the length of the arrayref rather than definedness as in my original code.

perl -e 'split//,q{john hurl, pest caretaker}and(map{print @_[$_]}(joi +n(q{},map{sprintf(qq{%010u},$_)}(2**2*307*4993,5*101*641*5261,7*59*79 +*36997,13*17*71*45131,3**2*67*89*167*181))=~/\d{2}/g));'


Comment on Re^3: concatenation of lines from two different files
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://633314]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2014-04-20 10:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls