in reply to Reading file contents
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Reading file contents
by Dramton (Initiate) on Jul 05, 2011 at 01:39 UTC | |
by Anonymous Monk on Jul 05, 2011 at 01:49 UTC | |
by Dramton (Initiate) on Jul 05, 2011 at 04:02 UTC | |
by Dramton (Initiate) on Jul 05, 2011 at 02:11 UTC | |
by Anonymous Monk on Jul 05, 2011 at 02:29 UTC |