in reply to pointing a filehandle at a scalar or array ?

You could do something using tie. The docs for tie in 5.005_03 cover tieing filehandles but it's not mentioned in Perl In A Nutshell so I'm not sure when this support was added.

Update:
In fact there seems to be a Tie::Handle module that would serve as a base class for this. It's part of the standard distribution.

--
<http://www.dave.org.uk>

European Perl Conference - Sept 22/24 2000, ICA, London
<http://www.yapc.org/Europe/>
  • Comment on Re: pointing a filehandle at a scalar or array ?

Replies are listed 'Best First'.
RE: Re: pointing a filehandle at a scalar or array ?
by jettero (Monsignor) on Jul 26, 2000 at 15:57 UTC
    Besides all other answers to this question, I'm desperate to see how this is done. I've blown 10 minutes of my life (so far) trying to figure out how to use Tie::Handle. If I figure it out I'll certainly post it here, but I'd rather that someone else figure it out and tell me. :)

    update: I think I got it! That bugged the s**t outta me for 30 minutes. Learn something new every day eh?

    #!/usr/bin/perl my $damn_string = "This is so cool...\nThis is less cool.\nThis sucks. +\n"; tie *H, 'str', $damn_string; while(<H>) { print "$_\n"; } package str; use Tie::Handle; my @a; sub TIEHANDLE { my $i = bless \$i, shift; @a = split "\n", shift; return $i; } sub READLINE { return shift @a; }