html - Perl file I/O issue -


i'm developing perl script that's supposed generate html file numerical values other file. idea read file has these values , list them in separate html file. file contains numerical values updated every period of time, , changes should seen on html.

even though these values correctly read (i've tested it) not printed in html. whats-more, html tags not printed. code i've written:

#!/usr/bin/perl use io::handle; use cgi qw(:standard);  print "status: 200 ok", "\n"; print "content-type: text/plain", "\n\n";  for(;;) {     open (my $input_file, "<", "/path/to/input/file/input_file.txt") || die "unable open file: $!";     open (my $html_file, ">", "/path/to/html/file/index.html") || die "unable open html file: $!";     print $html_file "<html><head><title>title</title><meta http-quiv='refresh' content='10'></head><body>";     @lines = <$input_file>;     foreach $line (@lines) {         print $html_file "<p>$line</p>";     }     print $html_file "</body></html>";     sleep 1;     close $input_file || die;     close $html_file || die;  } 

the script works in first for iteration. mean html tags , numerical values correctly printed in output file. then, iteration 2 n, file remains literally empty. can not see i'm missing here. why work in first iteration not in following ones?

thanks in advance

you need close file before sleep. stands, data flushed file close , overwritten next open, , left empty 1 second

you need write

close $html_file or die $! 

as code have equivalent to

close($html_file || die) 

so program never die long $html_file true


Comments