7. File Access


(in "/usr/local/widgets/data"
   (until (eof)
      (and (sub? "blue" (line T)) (prinl @)) ) )
(setq Var (in NIL (till NIL T)))  # Read standard input till EOF
(out LogFile ...)

(setq Fd (open LogFile))
(close Fd)
(out "+LogFile"  # switch to LOGFILE for output
   (prinl "Countdown initiated ...") )
# return to original output
(prinl "You have 30 seconds to reach minimum safety distance.")

Opening a File

(in "file"  # Open for input
   .. )

(out "file"  # Open for output
   .. )

(out "+file"  # Open for output (appending)
   .. )

Opening Files with Unusual Filenames


# Just like any other file, right?

Expanding Tildes in Filenames

Making Perl Report Filenames in Errors

Creating Temporary Files

Storing Files Inside Your Program Text

Writing a Filter

Modifying a File in Place with Temporary File

Modifying a File in Place with -i Switch

Modifying a File in Place Without a Temporary File

Locking a File

Flushing Output

Reading from Many Filehandles Without Blocking

Doing Non-Blocking I/O

Determining the Number of Bytes to Read

Storing Filehandles in Variables

Caching Open Output Filehandles

Printing to Many Filehandles Simultaneously

Opening and Closing File Descriptors by Number

Copying Filehandles

Program: netlock

Program: lockarea