Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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,

#!/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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://852970]
[stevieb]: Perhaps my experience with HP is a bit different as I always bought the highest end models through business.
[Corion]: 1nickt: At least the machines that $work is introducing to replace the Lenovo T60 here do not inspire confidence with me

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (19)
As of 2017-03-27 13:31 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (320 votes). Check out past polls.