Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Join files using perl

by Cristoforo (Deacon)
on Jan 11, 2013 at 20:17 UTC ( #1012970=note: print w/ replies, xml ) Need Help??


in reply to Join files using perl

Using this data (file 1 and file 2):

ID1 50 ID2 60 ID3 100
ID1 20 ID2 100 ID3 10
I got the results:
C:\Old_Data\perlp>perl t9.pl o44.txt o55.txt ID1 50 20 ID2 60 100 ID3 100 10 C:\Old_Data\perlp>
The code is:
#!/usr/bin/perl use strict; use warnings; my %data; while (<>) { # reads 2 files from @ARGV - filenames are on the command + line my ($id, $val) = split; push @{ $data{$id} }, $val; } for my $id (sort keys %data) { print join("\t", $id, @{ $data{$id} }), "\n"; }


Comment on Re: Join files using perl
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (12)
As of 2015-07-05 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls