[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: perl file i/o



Guy is right , but it should be:
 open FH, "+>>$file"
see
http://www.eprotect.com/stas/TULARC/webmaster/myfaq.html
#How do I modify my file by opening it only once:

I hope it will help you

If you want to read a realy nice perl stuff , read:
The WebTechniques Perl Columns- monthly column for Web Techniques magazine
(by     Randal L. Schwartz ) 
http://www.stonehenge.com/merlyn/WebTechniques/

The Unix Review Perl Columns - bi-monthly column for Unix Review
magazine (by     Randal L. Schwartz ) 
http://www.stonehenge.com/merlyn/UnixReview/

That's where I've learned about +>> stuff...


> 
> On Sat, 6 Dec 1997, shahar shocron wrote:
> 
> > open(FILE, "+<$file");
> > while(<FILE>);
> > {
> >   &change_record;
> >   print FILE $new_record;
> > }
> > close(FILE);
> 
> 1. is the record you're writing of the exact same size as the record
>    you're reading? if not, this method cannot work.
> 
> 2. if the answer to '1' is 'yes', then after each read, you need to seek
>    backwards in the file (using the perl 'seek' function) the ammount of
>    characters you've read, and then you may write on top of that record.
> 
> 3. if the answer to '1' is 'no', then you cannot write to the same file -
>    create a temporary file, write everything to it, and after you've done
>    and closed both files, rename the new file to the old file's name (this
>    will also remove the old file from the system).
> 
> 4. check the return value of any function call you make (open, close,
>    print) to look for errors - if youll assume they always work, you'll
>    get very buggy programms...
> 
>    this has nothing to do with perl - it has to do with any programming
>    language.
> 
> guy
> 
> 



______________________________________________________________________
Stas Bekman     mailto:sbekman@iil.intel.com [just another webmaster]
Linux Installation Party [Technion] http://instaparty.israel.eu.org/
Home Page:      http://www.eprotect.com/stas
A must visit: 	http://www.eprotect.com/stas/TULARC (Java,CGI,PC,Linux)
Linux-il Home:  http://www.linux.org.il/