Fingo has asked for the wisdom of the Perl Monks concerning the following question:

sub rtdeposit { #Please see NOTE at the top of this file open(WRITERT, ">rt.log") || die "Cannot open rt.log"; print "\nStarting Month:"; chomp($smon = <STDIN>); print "\nStarting Day:"; chomp($sday = <STDIN>); print "\nStarting Year (4 digit):"; chomp($syear = <STDIN>); print "\nDuration in Days:"; chomp($dur = <STDIN>); print "\nAmount to Add:"; chomp($add = <STDIN>); print "\nDescription:"; chomp($desc = <STDIN>); $sdate = Date_to_Days($syear,$smon,$sday); print WRITERT "deposit\n$add\n$dur\n$desc\n$sdate"; reload(); }
This is a peice of some horrible code I wrote which I intend to fix (Im very much a newbie) WRITERT writes to a file called rt.log, what stumps me is that t does not write all of the feilds in the file. Can anybody tell me my mistake? thanks

Replies are listed 'Best First'.
Re: Very weird
by Yohimbe (Pilgrim) on Feb 15, 2001 at 03:50 UTC
    even a simple  close WRITERT; before the reload(); call would fix it.
    --
    Jay "Yohimbe" Thorne, alpha geek for UserFriendly
      Yes thats it!!! WHy didnt I think of that? thanks man, I hope it'll work now..
(ichimunki) Flush your buffers when writing/reading files
by ichimunki (Priest) on Feb 15, 2001 at 03:28 UTC
    Did you flush the buffer or close the file at some point before reading from it?
      I don't think so. I modified it to create the array of the file, then close it before creating a >> filehandle. I would send you the whole code, but I'm afraid youd either a) vomit, b) try to kill me ;)
        Actually, I meant that you will need to do one of those two things before reading from the file (but after you print to the filehandle). Otherwise the missing field(s) sit waiting to be written to disk.