[Mastering-perl] First Peek: Tied Variables
Yitzchak Scott-Thoennes
sthoenna at efn.org
Wed Feb 8 21:02:19 EST 2006
On Wed, Feb 08, 2006 at 10:28:56AM -0600, brian d foy wrote:
> On 2/8/06, Yitzchak Scott-Thoennes <sthoenna at efn.org> wrote:
> > On Tue, Feb 07, 2006 at 11:29:31PM -0600, brian d foy wrote:
> > > I thought about tying just the {IO} portion of a scalar, but then I
> > > need a package variable, which I think is worse than the
> > > bareword. Oh well.
>
> > Need a package variable? For what?
>
> > BTW, you can do
>
> > tie *{$fh}
>
> how would that work, though? This code:
>
> my $fh;
> my $object = tie *{$fh}, $class, $output_file;
>
> gives this error:
>
> Can't use an undefined value as a symbol reference
>
> It seems to me that it's looking for something in the symbol table.
> How would you get a globref otherwise?
my $fh = \do {local *FH};
(which does have the side-effect of creating a *FH symbol table entry,
though $fh doesn't refer to it) or
use Symbol; # available from 5.002 on
my $fh = gensym();
More information about the Mastering-perl
mailing list