in reply to Re: IO::File is gimp.
in thread IO::File is gimp.

Because IO::File is a blessed symbol underneath the hood, I don't think was possible to store per-object state as well.

Sure it is! You just have to reach into the typeglob slots. It's ugly (so ugly that I won't show it here), but it's possible.

Replies are listed 'Best First'.
Re^3: IO::File is gimp.
by shmem (Chancellor) on Aug 12, 2007 at 21:53 UTC
    Ugly? C'mon, it's perl...
    my $fh = IO::File->new; *{$fh} = \ "foo"; # we'll split at foo $fh->open("< $file") or die "barf: $!"; my @ary; { local $/ = ${*{$fh}{SCALAR}}; @ary = <$fh>; }

    :-)

    update: a bit less ugly:

    { local $/ = $$$fh; @ary = <$fh>; }

    More ugly:
    You could also shoehorn a hash reference reference into the typeglob SCALAR slot to associate more stuff with it:

    *{$fh} = \ { input_record_separator => "foo" }; { local $/ = $$$fh->{input_record_separator}; @ary = <$fh>; }

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re^3: IO::File is gimp.
by demerphq (Chancellor) on Aug 12, 2007 at 21:57 UTC

    Socket does this IIRC.

    ---
    $world=~s/war/peace/g