My script opens a file, reads it or creates it/writes data to it, and displays the contents. The problem is nothing is read when opening the file. I've verified the file is written to by opening it with Notepad.
Here's the script:
use strict 'vars';
use warnings;
use Fcntl;
use POSIX;
use POSIX qw(setsid);
use POSIX qw(:errno_h :fcntl_h);
File_Data();
sub File_Data
{
my $path = "fd_search.txt";
my $create = 0;
my $write = 0;
my @temp = "";
sysopen(my $FH,$path,O_RDONLY) or $create = 1;
if (not $create)
{
@temp = <FH>;
if (not @temp)
{
$write = 1;
close($FH);
}
}
if ($write || $create)
{
if ($create)
{
sysopen(my $FH,$path,O_CREAT) or die "Could not create $path.";
close($FH);
}
sysopen(my $FH,$path,O_WRONLY) or die "Could not open $path to wri
+te to.";
print $FH "one two three";
close($FH);
sysopen(my $FH,$path,O_RDONLY) or die "Could not open $path the 2n
+d time";
@temp = <FH>;
}
close($FH);
my $count = 0;
print "<tr>\n";
print "<td>($count)@temp</td>\n";
print "</tr>\n";
}
Again, I can write to the file but can't read from it and can't figure out why?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.