Beefy Boxes and Bandwidth Generously Provided by pair Networks
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 ( [id://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 (Canon) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://932518]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-19 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found