Your question raises plenty of problems.

What exactly do you want to do? As the previous answers showed if you want to write to a file, then later on to read from it, you just need to close it in between. If you want to keep it open here is how you can do it:

#!/bin/perl -w use strict; open( NOTES, "+<note.txt") # +< allows you to do read/writ +e updates on the file or die "cannot open note.txt: $!"; print NOTES "stuff\n"; # print stuff in your file my $pos= tell NOTES; # mark the position before the +write you are interested in print NOTES "test\n"; # write your data (it should en +d up with \n if you want # <NOTES> to pick it up properl +y later) # when you are ready to read it seek NOTES, $pos, 0; # reset filehandle to the right + position my $fromfile=<NOTES>; # read chomp $fromfile; # rememebr that \n? You might w +ant to remove it now if ($fromfile eq "test") {print "Yes, this works"}

Now why would you want to do this over storing the data in an array or something similar, which would be way faster than playing with files? I have no idea (size of the data you actually write?)


In reply to Re: File Access by mirod
in thread File Access by dmckee

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.