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

On page 667 of the 3rd Edition of "Programming Perl", in the description of the record separator variable, it says: "Record mode mixes well with line mode only on systems where standard I/O supplies a read(3) function..."

I do not understant what the author means by "mixing" record mode and line mode. Either you read a file x bytes at a time, or you read it one line at a time,by whatever you want to call a line with the record separator, right? Am I missing something here? Is it possible to say, read up to 4096 bytes at a time, or up to a newline, whichever comes first by assigning a value to the $/ variable?

If I say $/=\128, does that literally mean read the file 128 bytes at a time, or something else?

I greatly appreciate any help in clearing this up,

tigervamp

Replies are listed 'Best First'.
Re: the Record Separator Variable
by iakobski (Pilgrim) on May 25, 2001 at 12:39 UTC
    You're not missing something, you can only read in either record mode or line mode. This is for each read of the file.

    So you could, if you really wanted, read a line, change $/ and then read in a fixed length record. I don't know why you would want to do this, and don't expect it to be portable.

    The "mixing" is per file, not per read.

    -- iakobski

Re: the Record Separator Variable
by bikeNomad (Priest) on May 25, 2001 at 19:43 UTC
    Mixing would refer to changing $/ on the fly. However, some operating systems (mainframes and VMS) have special file modes and don't allow both record mode and stream mode for the same file (you have to choose file types when you create the file).