Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Select only desired features from a text

by aaron_baugher (Curate)
on Mar 19, 2012 at 17:01 UTC ( #960446=note: print w/replies, xml ) Need Help??

in reply to Select only desired features from a text

The basic answer is to make a hash from the relationships in input1, and use that to parse and process the information you need from input2. If I understand your problem, in this case I would probably create a hash of arrays, keyed on the values from column4, so I'd have something like this:

%hoa = ( 'frog-n' => ['alligator-n'], 'crocodile-n' => ['alligator-n'], );

(I'd use a hash of arrays instead of a simple hash because I assume other values from column1 could have a relationship with 'frog-n'. If that's not true, then this could be a simple hash.) Even if input1 is 4GB, since you're only interested in parts of certain lines, your hash may be much smaller.

Then I'd start going through input2, building a new multilevel hash based on the array elements from %hoa, with sub-keys from the new file, so I would be assigning values like this:

# from the first line: frog-n about adage-n 8.8016 for $key (@$hoa{frog-n}){ $newhash{$key}{about}{adage-n} += 8.8016; }

That will sum up repeated patterns as it goes, and it won't matter if they are consecutive. When it's done, go through that second hash and print it out in whatever format you like. There are still details to work out (like if you really want the sum elements displayed next to the sum like that, you may want to store them as an array and sum them in the last step), but that's the basic structure.

Aaron B.
My Woefully Neglected Blog, where I occasionally mention Perl.

Replies are listed 'Best First'.
Re^2: Select only desired features from a text
by Anonymous Monk on Mar 19, 2012 at 22:19 UTC
    Aaron, thanks a lot. I tried writing my code based on your suggestions and I succeeded. Thanks!!!!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://960446]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2018-02-25 18:24 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (314 votes). Check out past polls.