Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Looping in a Loop

by VinsWorldcom (Prior)
on Sep 16, 2014 at 13:39 UTC ( [id://1100763]=note: print w/replies, xml ) Need Help??


in reply to Looping in a Loop

UPDATE: Athanasius beat me to the punch with both a 'welcome' and a better 'Perl-ish' solution!

Violet, first off, welcome to the Monastery and to the wonderful world of Perl programming.

First off, start all your scripts with 'use strict' and 'use warnings', that will help you catch many errors and incorrect or troubling syntax that may impact your output and obfuscate troubleshooting.

You should use the three-argument 'open' for better security in your code.

The main problem I see is that you operate on FILE while in the LIST loop. You should do the operations on FILE outside the LIST loop. I've provided reference below that works on a small test data set I made up (assuming what your input files look like based on your question and code).

#! C:\Perl\bin\perl -w use strict; use warnings; open my $LIST, '<', "list.txt"; my @mylist = <$LIST>; open my $FILE, '<', "file.txt"; my @myfile = <$FILE>; foreach my $file (@myfile) { chomp $file; my @temp = split (/\t/, $file); foreach my $list (@mylist) { chomp $list; if ($temp[1] eq $list) { print "$file\n" } } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-23 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found