Re: looping issue
- From: rthangam <ramesh.thangamani@xxxxxxxxx>
- Date: Mon, 30 Jun 2008 02:07:26 -0700 (PDT)
On Jun 30, 12:45 pm, dakin999 <akhils...@xxxxxxxxx> wrote:
Hi, I have following code:
foreach my $row (@$array_ref) {
my ( $usr, $usr_det, $pwd_val) = @$row;
#print "\tuser id :$usr\n";
#print "\tcard no :$usr_det\n";
#print "\tpasswd :$pwd_val\n";
open (FILE, "<file_name") || die "Could not open the file: $!";
while (<FILE>) {
chomp;
(my $nusr_id) = split(); #read into a variable
--
--
--
}
}
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.
Any suggestions for doing this??
You can do it this way. Open the file before the for ... loop and use
readline() function which accepts the filehandle as parameter to get a
line at a time. For eg.,
open(FH,"test.txt") or die $!;
my $line = readline(FH);
print $line;
$line = readline(FH);
print $line;
You can also try some other modules like FileHandle which is object
oriented and also has methods like getline(), getlines() etc.
.
- Follow-Ups:
- Re: looping issue
- From: Tad J McClellan
- Re: looping issue
- References:
- looping issue
- From: dakin999
- looping issue
- Prev by Date: Re: looping issue
- Next by Date: editing smb.conf (INI files)
- Previous by thread: Re: looping issue
- Next by thread: Re: looping issue
- Index(es):
Relevant Pages
|