use of next versus last in a nested loop algorithm
- From: "markpark" <mark.leeds@xxxxxxxxxxxxxxxxx>
- Date: 16 Oct 2006 13:00:29 -0700
this is my last question of the day, i promise.
the code below is doing something very straightforward : i may have a
datelist array say ( 200601, 200603, 200602) and a filelist array say
( eurusd.20060123.txt, eurusd.20060523.txt, eurusd.20060622.txt ). all
i want to do is write the .txt string to a file whenever there is a
match between it and any of the items in the datelist array. i think
below will work but i haven't tested it yet. but, my question is not
really about the code below exactly. filelist can have tons of items in
it, so if there is a match, i want to get
out of the foreach my $pat loop and go to the next $item in the
foreach my $item loop on the outside. i've read about next and last in
various books and still i can't tell what to use because
my case is a little different than the examples in the books because i
am comparing values in
the two loops to decide when to get out. therefore, i don't think
whatever statement i use, next
or last, can go in the if statement ?
foreach my $item (@filelist) {
foreach my $pat (@datelist2array) {
if ( $item =~ /$pat/ ) {
print $out_file2 "$item \n";
}
}
}
thanks a lot. i'm very sorry to bother everyone.
.
- Follow-Ups:
- Re: use of next versus last in a nested loop algorithm
- From: Mumia W. (reading news)
- Re: use of next versus last in a nested loop algorithm
- From: Paul Lalli
- Re: use of next versus last in a nested loop algorithm
- Prev by Date: Undefined subroutine &main::1 called perl script
- Next by Date: Re: Problem setting a (multiple) value using HTML::Form
- Previous by thread: Undefined subroutine &main::1 called perl script
- Next by thread: Re: use of next versus last in a nested loop algorithm
- Index(es):
Relevant Pages
|