Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
We don't bite newbies here... much
 
PerlMonks  

Re^2: I need help joining tab-delimited files/tables!

by daptal (Acolyte)
on Oct 19, 2011 at 22:19 UTC ( #932518=note: print w/ replies, xml ) Need Help??


in reply to Re: I need help joining tab-delimited files/tables!
in thread I need help joining tab-delimited files/tables!

An alternative solution to the above would be something like this

my @files = ('file1','file2','file3','file4'); # use a glob if you prefer my %hash; foreach my $file_name (@files){ open my $fh, '<',$file_name || die "$!"; while (<$fh>){ chomp; next if (/^\s*$/); my ($id,$val) = split /\t/; $hash{$id}{$file_name} = $val; } close $fh; } foreach my $id (sort keys %hash){ print "$id\t"; print $hash{$id}{$_} ? "$hash{$id}{$_}\t" : "0\t" foreach (@f +iles); print "\n"; }


Comment on Re^2: I need help joining tab-delimited files/tables!
Download Code
Re^3: I need help joining tab-delimited files/tables!
by NetWallah (Monsignor) on Oct 20, 2011 at 03:50 UTC
    Your "open" statement has the "Operator precedence" problem described in die on file open.

                "XML is like violence: if it doesn't solve your problem, use more."

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2014-04-17 07:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (440 votes), past polls