CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
How can I loop through each line till end of file?

 



alantyss
Deleted

Jul 28, 2000, 9:21 AM

Post #1 of 3 (537 views)
How can I loop through each line till end of file? Can't Post

I need to loop through a log file called rawdata.wrk where I take the first line then parse it into the variables below and then process it and then loop through to the next line and apply the same thing and leave the loop once all lines in the file has been processed. Here is what I have so far and for some reason it is given me an infinite loop. Can someone please help me? Thanks

open RAW, "<rawdata.wrk")
or die "Cannot open rawdata.wrk; $!\n";
($vdate, $id, $vtime, $job_string, $clock_IP, $host_IP, $type)= split(/,/);

while()
($vdate, $id, $vtime, $job_string,
$clock_IP, $host_IP, $type)= split(/,/);

if (($vdate < $ndate) && ($vtime < $ntime))
{
print OUTFILE "good";
}
else
{
print OUTFILE "hello\n";
system(1,"time $ntime");
system(1, "date $ndate");
}
}


Kanji
User

Jul 28, 2000, 9:31 AM

Post #2 of 3 (537 views)
Re: How can I loop through each line till end of file? [In reply to] Can't Post

 http://www.perlguru.com/forum/Forum2/HTML/000620.shtml

In your case, while (<RAW> ) { instead of while().

You probably also want to remove the first split(/,/) line as it's not operating on the contents of the file but rather whatever else $_ happens to be set to at the time.


dws
Deleted

Jul 29, 2000, 10:46 AM

Post #3 of 3 (537 views)
Re: How can I loop through each line till end of file? [In reply to] Can't Post

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

while ( <RAW> ) {
chomp; # so $type doesn't end up with a "\n" in it.
...
</pre><HR></BLOCKQUOTE>

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives