Re: looping issue



dakin999 <akhilshri@xxxxxxxxx> wrote:
foreach my $row (@$array_ref) {
[...]
open (FILE, "<file_name") || die "Could not open the file: $!";
while (<FILE>) {
chomp;
(my $nusr_id) = split(); #read into a variable
--
--
--
}
}

This code reads and loops through all of <FILE> for each element of
@$array_ref.

The problem is in the looping of input <FILE> that I need to read for
each $row. Basically there can be more than 1 $row values and I need
to pick a new line from <FILE> for each $row entry.

Are you saying that is not what you want but instead you want to loop
through @$array_ref and <FILE> in sync, i.e. for each element of
@$array_ref read exactly one line of <FILE>?
If so, then just do it:

open (FILE, "<file_name") || die "Could not open the file: $!";
foreach my $row (@$array_ref) {
[...]
$_ = <FILE>;
chomp;
(my $nusr_id) = split(); #read into a variable
--
--
--
}

jue
.



Relevant Pages

  • Re: foreach enhancement
    ... Additionally we were talking about stating increment values for cases like ... Extra syntax would be required and ... project only to make its loops look better and perform much slower. ... But if you simply could write foreach wouldn't you used ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C# very optimisation
    ... >>> Another way to make your code faster is to never use foreach loops. ... where the iteration is actually the bottleneck. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: foreach loops are sooooo tricky.....
    ... loops are not at all like for loops, ... Translating Fortran to PHP, because hosters won't allow anything else ... I wish PHP would do array and matrix stuff like Fortran or C, ... I find foreach loops to be quite intuitive. ...
    (comp.lang.php)
  • Re: regex help
    ... foreach ... chomp; ... open (pkgREPO, '<', 'data/versions-list.txt') ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx with a subject of "unsubscribe". ...
    (Debian-User)
  • Re: Anything wrong with the way I use "break"s in my loops?
    ... There isn't anything logically wrong the way you use "break" twice to get out of the 2 loops, but a few lines of tedious code. ... foreach ... origWeight = bu.OriginalWeight; ...
    (microsoft.public.dotnet.general)