http://qs1969.pair.com?node_id=873345


in reply to how to read every 10 line from input text file ?

sleep after every 10th line. See also $.
open (FILE,"file.txt"); while (my $data = <FILE>) { chomp($data); print ("$data\n"); sleep 60 if $. % 10 == 0; } close(FILE);

Replies are listed 'Best First'.
Re^2: how to read every 10 line from input text file ?
by avanta (Beadle) on Nov 24, 2010 at 03:32 UTC

    "toolic" code will make it sleep at 10th line but if u need to read every 10th line following is the modified code
    open (FILE,"file.txt"); while (my $data = <FILE>) { if($. % 10 ==0) { chomp($data); print ("$data\n"); sleep 60; } } close(FILE);
    Thanks
    AvantA
Re^2: how to read every 10 line from input text file ?
by chrestomanci (Priest) on Nov 24, 2010 at 10:00 UTC

    Lets not use the abbreviated perl predefined variables, that confuse newbies, and are partly responsible for perl's reputation as a read only language. Instead can I suggest:

    use English '-no_match_vars'; ... sleep 60 if 0 == ($INPUT_LINE_NUMBER % 10)

    Or better still:

    sleep 60 if 0 == (FILE->input_line_number() %10)
      Lets not pretend like that has any truth to it, or that anyone actually uses English module