Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Aligning text and then perfom calculations

by shmem (Canon)
on Dec 15, 2013 at 22:01 UTC ( #1067259=note: print w/ replies, xml ) Need Help??


in reply to Aligning text and then perfom calculations

The data you present is perfect for a hash (see perldata), since each row consists of a key (e.g. "politici") and a value (0.0489). You have two files with that structure, so you set up two hashes. You can then iterate over the keys of one hash with keys and see if it is present in the other hash with exists. Then access the corresponding values of both hashes and do your calculation.

for my $key (keys %left) { if ( exists $right{$key} ) { my result = $left{$key} - $right{$key}; print "$key | $result\n"; } }

Storing the key/value tupels from the files into the hashes %left and %right is left as an exercise to the reader.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'


Comment on Re: Aligning text and then perfom calculations
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2014-08-02 02:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (53 votes), past polls