Hi, you are trying to read from the file while you have it open for writing. You should read the current values, then do your processing, then open for writing (if you have anything to write).

Update: I don't believe you are reading from the file with "+>>", now that I test it:

$ perl -MPath::Tiny -Mstrict -Mautodie -wE ' my $file = Path::Tiny->tempfile; open my $FH, ">", $file; print $FH "$_\n" for qw/foo bar baz/; close $FH; open my $FH2, "<", $file; print "2: $_" while (<$FH2>); close $FH2; open my $FH3, "+>>", $file; print "3: $_" while (<$FH3>); print $FH3 "I was here"; close $FH3; open my $FH4, "<", $file; print "4: $_" while (<$FH4>); close $FH4; '
Output:
2: foo 2: bar 2: baz 4: foo 4: bar 4: baz 4: I was here

Hope this helps!


The way forward always starts with a minimal test.

In reply to Re: Writing to File based on condition by 1nickt
in thread Writing to File based on condition by cbtshare

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.