use of next versus last in a nested loop algorithm



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.

.



Relevant Pages

  • Re: Count Lines in (Huge) Text Files
    ... A few years ago, I was doing some high-throughput disk stuff and my recollection is that I found the same thing you did: larger buffers only helped up to about 8K or so, and past that any improvement was minimal. ... me that with appropriate settings for its buffer, it should perform better, since it ought to be optimized for line-based i/o. ... Assuming what's hurting you in the explicit forloop is the retrieval of the data and not the counter increment, the above should perform basically as well as a plain foreach() loop. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: a question about for and foreach
    ... foreach (@array) { ... why @array are changed after this foreach loop!!! ... The "foreach" loop iterates over a normal list value and sets the ... If any element of LIST is an lvalue, you can modify it by modifying ...
    (perl.beginners)
  • Re: use of next versus last in a nested loop algorithm
    ... out of the foreach my $pat loop and go to the next $item in the ... foreach my $item loop on the outside. ... my case is a little different than the examples in the books because i ...
    (comp.lang.perl.misc)
  • Re: Lost data on socket - Can we start over politely?
    ... $clsel as a single-element-holding object containing the current ... simply performing the following check on $sel instead of $clsel? ... removing elements from something from a list used for the loop is a Bad ... Doesn't that throw the foreach() loop out of sync? ...
    (comp.lang.perl.misc)
  • Re: Re: Last row in foreach loop
    ... foreach loop other then setting up a loop counter that you manually ... foreach (Racecar racecar in RaceCarCollection) ... almost as reasonable to put the processing into a separate method and th= ...
    (microsoft.public.dotnet.languages.csharp)