When I run your code I get:
"my" variable $FH masks earlier declaration in same scope at C:\Users\ +Peter\Delme~~\PerlScratch\noname1.pl line 36. readline() on unopened filehandle FH at C:\Users\Peter\Delme~~\PerlScr +atch\noname1.pl line 38. <tr> <td>(0)</td> </tr>
which tells you exactly what jethro and d5e5 determined for you. Using strictures is good, but they only work for you if you take notice of the warnings and errors they issue!
A few other tips: avoid needless initialisation. Use sensible and meaningful names. Take advantage of all failure information. Consider:
use strict; use warnings; use Fcntl; use POSIX qw(setsid :errno_h :fcntl_h); File_Data(); sub File_Data { my $path = "fd_search.txt"; my $create = !sysopen(my $inFile, $path, O_RDONLY); my $write; my @data; if (not $create) { @data = <$inFile>; $write = !@data; close $inFile; } if ($write || $create) { if ($create) { sysopen(my $outFile, $path, O_CREAT) or die "Create $path failed: $!"; close $outFile; } sysopen(my $outFile, $path, O_WRONLY) or die "Create $path fai +led: $!"; print $outFile "one two three"; close $outFile; sysopen(my $inFile, $path, O_RDONLY) or die "Reopen $path fail +ed: $!"; @data = <$inFile>; } print "<tr>\n"; print "<td>(0)@data</td>\n"; print "</tr>\n"; }
In reply to Re: Reading file contents
by GrandFather
in thread Reading file contents
by Dramton
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |