Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: how to read every 10 line from input text file ?

by toolic (Bishop)
on Nov 24, 2010 at 01:44 UTC ( [id://873345]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://873345]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-18 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found