Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^9: Compare hash with arrays and print

by almut (Canon)
on Jul 13, 2010 at 19:25 UTC ( [id://849358]=note: print w/replies, xml ) Need Help??


in reply to Re^8: Compare hash with arrays and print
in thread Compare hash with arrays and print

When I try running my script with the following test set , it does not print anything in the output files, instead prints the data onto the screen!

This is most likely because with

my ($name) = /^([^\n]+)/;

you're extracting the entire header line as $name to be used as the hash key, but you have not set up your hash accordingly with keys such as "001.b1 gnl|ti|10009".  In this case, none of the select FILE1 statements would execute, so STDOUT (connected to the screen) remains the default output handle for print.

Note that ^([^\n]+) would match everything from the beginning of the record up to the first newline, because the character class [^\n] says "match any character but a newline" (the ^ within the class negates).

Try one of the other suggestions, or adjust the regex as needed.

Replies are listed 'Best First'.
Re^10: Compare hash with arrays and print
by ad23 (Acolyte) on Jul 13, 2010 at 21:19 UTC

    Gosh! I didn't notice that at all. But now I understand!

    This seem to run perfectly fine with my test data. However my actual data files are huge.

    Thanks a tonne again almut. I really appreciate your help!

Re^10: Compare hash with arrays and print
by ad23 (Acolyte) on Jul 14, 2010 at 13:32 UTC

    Hi...

    Since I am comparing my keys from hash, shouldn't it print out the results in a sorted manner?

    Do I need to use an array to sort these separately?

    Thanks!!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2026-01-13 18:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (118 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.