Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Merging two list with simple operation

by rir (Vicar)
on Aug 04, 2010 at 21:01 UTC ( [id://852970]=note: print w/replies, xml ) Need Help??


in reply to Re: Merging two list with simple operation
in thread Merging two list with simple operation

I'll endorse ahmad's solution. I'd just point out that the magical quality of @ARGV can be handy for this kind of data munging and that chomp %hash chomps the hash's values.

Be well,
rir

#!/usr/bin/perl use strict; use warnings; @ARGV = qw/ file1 file2/; my %h; while ( <> ) { /(\S+)\s+(\S+)/; $h{$1} = $h{$1} ? $h{$1}*$2 : $2; } print "$_ $h{$_}\n" for sort { $h{$a} <=> $h{$b} } keys %h;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-23 11:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found