[EMAIL PROTECTED] wrote:
>
> The following snippet is from "Advanced perl programming" by Sriram
> Srinivasan. A test program is also attached.
> If I print any other list element, it works fine but for
> the first element ( $array[1] ), it gives a warning. What's on??
> Perl version is 5.6.0 on RH Linux 7.
This is an error in the published code (I've submitted an errata to
O'Reilly.)
> /home/atul/myperl> ./tst.pl
> Use of uninitialized value in seek at /home/atul/myperl/TieFile.pm line 27.
> #!/usr/bin/perl -w
> /home/atul/myperl>
>
> ----------------- Example Program ( tst.pl ) ----------------
>
> [snip]
>
> ----------------- Example Program ( tst.pl ) ----------------
>
> --------------------- CUT HERE --------------------
>
> [snip]
>
> sub FETCH {
> my ($obj, $index) = @_;
> # Have we already read this line?
> my $rl_offsets = $obj->[$F_OFFSETS];
> my $fh = $obj->[$F_FILEHANDLE];
> if ($index > @$rl_offsets) {
Change this line to:
if ($index >= @$rl_offsets) {
> $obj->read_until ($index);
> } else {
> # seek to the appropriate file offset
> seek ($fh, $rl_offsets->[$index], 0);
> }
> return (scalar <$fh>); # Return a single line, by evaluating <$fh>
> }
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]