Tony wrote:
> Hi,
>
> I am trying to read the last 500 bytes of a file. I'm trying to use
> sysread command, I have read the docs for it on cpan and it seems the
> right thing to use.
> My only problem is when i spcify a negative offset it fails with the
> following error "Offset outside string at test.pl line 30.".
>
> here is the line it is complaing about
>
> sysread(F,$string,500,-500);
>
> I have tried escaping the minus sign , putting it into a var and using
> eval and they all come back with the same error.
>
> Heres the paragraph from cpans docs
>
> "An OFFSET may be specified to place the read data at some place in
> the string other than the beginning. A negative OFFSET specifies
> placement at that many characters counting backwards from the end of
> the string. A positive OFFSET greater than the length of SCALAR
> results in the string being padded to the required size with "\0"
> bytes before the result of the read is appended."
>
> should this work or is it just me reading the distructions wrong.
It's you

You are *reading* from the filehandle ( called F in your
example) and *writing* to $string. The offset specifies where in $string
you want to put the number of bytes specified in the 3rd parameter, not
where you start reading from the file.
If you want to read from the end of a file look at
perldoc -f seek
perldoc -q tail
or the modules
File::Tail
File::ReadBackwards
on CPAN
Thomas
--
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</ #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#.... >>e>r^..>l^...>k^..