Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Double While!

by NodeReaper (Curate)
on Mar 01, 2001 at 22:05 UTC ( [id://61597]=perlquestion: print w/replies, xml ) Need Help??

NodeReaper has asked for the wisdom of the Perl Monks concerning the following question:

Replies are listed 'Best First'.
Re: Double While!
by kilinrax (Deacon) on Mar 01, 2001 at 22:14 UTC
    I can see a number of things wrong here:
    • You aren't actually iterating over anything. Try 'while(<FILE1>)' rather than just 'while()'.
    • The second filehandle won't reset on each iteration of the outer loop. Try slurping the data into an array / hash instead.
    • You didn't use code tags. Try reading the FAQ.
    Here's a quick example of a better way to do this:
    #!/usr/bin/perl -w use strict; open(FILE1,"/tmp/file1") or die "Couldn't open /tmp/file1: $!"; open(FILE2,"/tmp/file2") or die "Couldn't open /tmp/file2: $!"; my @array; my %hash; while (<FILE1>) { chomp; push @array, $_; } while (<FILE2>) { chomp; $hash{$_} = ''; } close FILE1; close FILE2; foreach (@array) { if(exists $hash{$_}) { print "$_ matched!\n" } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-19 19:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found