Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Merging two list with simple operation

by rir (Vicar)
on Aug 04, 2010 at 21:01 UTC ( #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;


Comment on Re^2: Merging two list with simple operation
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2015-07-06 04:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls