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"; }
True laziness is hard work

Replies are listed 'Best First'.
Re^2: Reading file contents
by Dramton (Initiate) on Jul 05, 2011 at 01:39 UTC
    I'm not getting that error/warning.
      Sure you are, but maybe, just maybe, the it is in your error log
        I found the solution! :D I could've sworn it didn't work before. It took seing it in perlintro to try it again. :) Where I have <FH> in my script I added the '$' to make it <$FH> and now it shows the data that was written to the file. Thanks guys for helping. :) Hard long lesson learned :/
        Where would the error logs be located?