Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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"; }

Replies are listed 'Best First'.
Re^3: I need help joining tab-delimited files/tables!
by NetWallah (Abbot) 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 perusing the Monastery: (8)
As of 2016-06-27 23:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (348 votes). Check out past polls.