Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Compare hash with arrays and print

by jwkrahn (Abbot)
on Jul 12, 2010 at 19:02 UTC ( [id://849080]=note: print w/replies, xml ) Need Help??


in reply to Compare hash with arrays and print

Perhaps something like this will do what you require UNTESTED:

my %hash = ( aw1 => 10, qs2 => 20, dd3 => 30, de4 => 10, hg5 => 30, dfd6 => 20, gf4 => 20, hgh5 => 30, hgy3 => 10, ); { # exchange number values for filehandles open my $FILE1, '>', '10.txt' or die "Cannot open '10.txt' $!"; open my $FILE2, '>', '20.txt' or die "Cannot open '20.txt' $!"; open my $FILE3, '>', '30.txt' or die "Cannot open '30.txt' $!"; for my $val ( values %hash ) { $val = $FILE1 if $val == 10; $val = $FILE2 if $val == 20; $val = $FILE3 if $val == 30; } } local @ARGV = glob 'Data/*.fa'; my $name; while ( my $line = <> ) { if ( $line =~ /^>(.+)/ ) { $name = $1; } print { $hash{ $name } } $_ if exists $hash{ $name }; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2025-12-08 20:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (88 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.