Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: combining 2 files with a comon field

by ZlR (Chaplain)
on May 18, 2005 at 10:58 UTC ( [id://458146]=note: print w/replies, xml ) Need Help??


in reply to combining 2 files with a comon field

Hello jjohhn ,

This might be a little 'quick and dirty' but it does what you want, using a hash :

use strict ; use warnings ; my @file1 = ( 'A1|dog|', 'A2|cat|','A3|bird|' ) ; my @file2 = ( 'A1|Fido|','A2|Fluffy|','A3|Tweety|') ; my %rez ; foreach my $it (@file1) { my @input = split /\|/ , $it ; $rez{$input[0]} = join "|" ,"", @input[1,] ; } foreach my $it (@file2) { my @input = split /\|/ , $it ; $rez{$input[0]} .= join "|" ,"", @input[1,] ; } print $_, $rez{$_}, "\n" foreach ( sort keys %rez ) ;
Hope this helps :)
zlr_

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-18 11:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found