Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Need help with comparison code

by GotToBTru (Priest)
on Feb 02, 2011 at 18:16 UTC ( #885811=note: print w/ replies, xml ) Need Help??


in reply to Need help with comparison code

You have opened both IN and OUT using the same mode. You probably mean:

open IN,'<',$matchfile or die "Could not open $matchfile\n"; open OUT,'>>,$outfile or die "Could not open $outfile\n";
Foreach syntax: foreach $var (@array)
For syntax: for (expression; condition; control)
I think you want to use two foreach commands here:
foreach my $file (@files) { foreach my $file2 (<IN>) {


Comment on Re: Need help with comparison code
Select or Download Code
Replies are listed 'Best First'.
Re^2: Need help with comparison code
by GrandFather (Sage) on Feb 03, 2011 at 03:52 UTC

    for/foreach (<$fh>) is generally a bad idea - it implies slurping the file and creating a list of lines internally. Better is to use a while (<$fh>) loop. In both cases the loop body handles things a line at a time, but while is a better semantic match and is likely to be much more memory (and possibly slightly more time) efficient.

    True laziness is hard work
Re^2: Need help with comparison code
by Gulliver (Monk) on Feb 02, 2011 at 18:52 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (15)
As of 2015-07-07 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls