home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!wupost!sdd.hp.com!usc!news!netlabs!lwall
- From: lwall@netlabs.com (Larry Wall)
- Newsgroups: comp.lang.perl
- Subject: Re: problems opening a file read/write
- Message-ID: <1992Sep9.162322.7492@netlabs.com>
- Date: 9 Sep 92 16:23:22 GMT
- References: <1992Sep9.094428.16363@uvaarpa.Virginia.EDU>
- Sender: news@netlabs.com
- Organization: NetLabs, Inc.
- Lines: 33
- Nntp-Posting-Host: scalpel.netlabs.com
-
- In article <1992Sep9.094428.16363@uvaarpa.Virginia.EDU> krm%pri-mu.LOCAL@pri-mu.prime.com writes:
- : Hi net,
- :
- : I tried the following small piece of code:
- :
- : --------------------------------
- : #!/bin/perl
- : open(TEST,"+>tst")||die "open";
- : while($_=<TEST>){
- : if (/add/){
- : chop ;
- : $_.="ADD\n";
- : }
- : print TEST $_ || die "print";
- : }
- : close(TEST) || die "close";
- : --------------------------------
- :
- : Now the problem:
- :
- : If I use open with "+>filename", the file will end up empty.
-
- That's because +> will truncate a file, just like >. The + only opens
- it for both reading a writing. If you want to append to a file,
- use +>>.
-
- : If I use "+<filename", it will remain unchanged.
-
- This is probably a buglet in your stdio. Many versions of stdio require
- a seek between reads and writes. If you seek to the end of the file
- it should append.
-
- Larry
-