Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: match loop failure

by jwkrahn (Abbot)
on Jun 08, 2011 at 18:23 UTC ( [id://908759]=note: print w/replies, xml ) Need Help??


in reply to match loop failure

It looks like you want something like this:

my %hash; while ( <INFILE> ) { ( my $line = $_ ) =~ s/\s+$//; my ( $Rank, $id, $C, $Position ) = split /\t/, $line; next unless $Rank =~ /\d/; $hash{ $Rank } = "$id\t$C\t$Position"; } while ( <INFILE2> ) { ( my $line = $_ ) =~ s/\s+$//; my @b = split /\t/, $line; next unless $b[ 0 ] =~ /\d/; my $Start_rank = $b[ 1 ]; if ( exists $hash{ $Start_rank } ) { print join( "\t", $Start_rank, $hash{ $Start_rank }, @b[ 2 .. +9 ] ), "\n"; } else { print "no match\n"; } }

Replies are listed 'Best First'.
Re^2: match loop failure
by Anonymous Monk on Jun 10, 2011 at 08:22 UTC

    After correcting the foreach scalar to @b I was going through each of the 200,000 keys in my hash (creating a 20GB output file). Using your exist correction makes the script much quicker! Thank you!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-03-19 10:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found