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

This is interesting, since I've noticed a lot of people grumbling about this with modules that require globs (one of mine included). The true wizards can always overload a filehandle, using Tie::Handle if necessary. But what I was wondering is if anyone thinks it'd be worthwhile for me (or someone else, I suppose) to whip up a module to wrap up all of this overloading stuff into one convenient package. Say....Tie::UniversalHandle or something. So you could just do: tie *FH, Tie::UniversalHandle, $some_string; or tie *FH, Tie::UniversalHandle, @some_array; and have all of the magic immediately wrapped up insde of the module. It'd spare people the trouble of having to roll their own module every time.
  • 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 chip (Curate) on Jul 27, 2000 at 01:29 UTC
    When faced with this sort of problem, I've found it useful to just drop back one level of indirection and use subroutine references:

    my $gimme = $fh ? sub { <$fh> } : sub { pop @array }; ... while (defined($x = &$gimme)) { ... }