On Wed, Jun 13, 2001 at 01:30:07PM -0700, Esrar Chowdhury ([EMAIL PROTECTED]) wrote:
> Hi!
> 
> I just started using perl and have a question. Let say I have an inputfile
> with 100 lines. Each of these lines contain a name...first name and
> last name.
> 
> I need to be able to read the 1st name..the 10th name...20th name..so on 
> i.e. every 10th name from the input file.
> 
> I do :
> 
> $name = <INFILE>; #for the 1st line 
> 
> # have already opened my input file by
> 
> unless (open(INFILE, "test_input.txt")) {
> die ("Input file test_input.txt cannot be opened.\n");
> }
> 
> my question is...how do I make the read pointer read every 10th line
> from my input file? (After reading one line, does the read pointer stay
> on the same line or automatically go the next line?)

It's probably easiest to read every line, but only process every 10th one.

Something like this should do it:

while (<INFILE>) {
  next unless $. % 10; # skip line unless it's a multiple of 10

  # Do whatever processing you want
  # The line is in $_
}

hth,

Dave...

Reply via email to