.------[ Dan Muey wrote (2003/03/04 at 15:04:30) ]------
 | 
 |  > Long ago in GW Basic there were sequential files and random 
 |  > access files. Does perl have the latter? I only to get (and 
 |  > then put) certain info in a certain place every time. If I 
 |  > can avoid writing the whole file every time I bet my web site 
 |  Every time what??
 |  
 |  
 |  I'm not familiar with GQ Basic but there's lots of ways to modify files.
 |  
 |  How big is your file?What format?
 |  
 |  I'd use File::Slurp. Although you may still be writing the entire file 
 |  
 |  If you just did 
 |  
 |  use File::Slurp;
 |  
 |  $contents = read_file("myfile.txt");
 |  $contents .= "Here is a new line for my file!\n";
 |  write_file("myfile.txt", $contents);
 |  
 |  That script takes not quite one second for a 2.5 megabyte file for me.
 |  If that puts your hosting provider in a pinch then I'd get another 
 |  hosting provider!!!
 |  
 |  DMuey
 |  
 `-------------------------------------------------

    No offense, but this isn't very efficient. It might be fine on a 2.5
    MB file, but what about a 2,500 MB one? I bet your hosting company
    would freak out then.  Try this instead: 

    open(OUT, ">>myfile.txt"); 
    print OUT "Here is a new line for my file!\n"; 
    close(OUT); 

    The above will append a line of text onto the end of the file
    without the need to "slurp" the entire thing into RAM.  

    I'm of the opinion that you shouldn't slurp an entire file into RAM 
    ever.  Even if you have the RAM to spare, even if the file is small,
    etc, it's just not a good practice to get into. 

    As to the original question, Perl does have similar concepts to
    sequential and random access files. They aren't much like GW Basic 
    however. 

    I would suggest reading up on on your Perldoc for open() and sysopen(), 
    probably reading the Perl Cookbook would be a good idea to get a better
    handle on this stuff. 

 ---------------------------------
   Frank Wiles <[EMAIL PROTECTED]>
   http://frank.wiles.org
 ---------------------------------


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to