On Sun, 2008-11-23 at 15:52 +0800, loody wrote:
> Dear all:
> The prototype of read is
> read FILEHANDLE,SCALAR,LENGTH
> ex:
> read PATTERN, $line, 1920;
> 
> that means the $line will content 1920 bytes.

It means it will attempt to read 1920 bytes.  The actual number of bytes
read is returned.  Your code should look something like this:

my $bytes_read = 0;
while( $bytes_read = read( PATTERN, $line, 1920 ) ){
  # do something with $line
}
if( ! defined( $bytes_read ) ){
  die "error reading PATTERN: $!\n"
}

> if I want to modify the byte offset 720 of $line, it seems impossible,
> since $line is a scalar not an array.
> I know I can read a byte to each array element one by one, but it
> seems pretty slow.
> 
> Is there any read file function can read in the file content to an array?
> appreciate your help,
> miloody
> 

Not the read function but you can use unpack.  See `perldoc -f unpack`
and `perldoc -f pack` for details.


-- 
Just my 0.00000002 million dollars worth,
  Shawn

The map is not the territory,
the dossier is not the person,
the model is not reality,
and the universe is indifferent to your beliefs.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to