But what happens when you want to pass a format or dirhandle to a subroutine instead of a filehandle.Although globs are synonymous with filehandles they aren't really the same thing. It's just that perl will DWYM when you provide a reference to a glob with an IO reference in it
So if you use a glob or a reference to a glob where a filehandle is expected and the glob doesn't contain a valid IO reference then it evaluates to undef e.g$FH = "a scalar"; @FH = qw/an array/; %FH = (a => 'hash'); open(FH, "somefile.txt") or die("dang - $!"); for(qw/SCALAR ARRAY HASH IO/) { print $glob, "{$_} = ', *{$glob}{$_}, $/; } print while <$glob>; __output__ *main::FH{SCALAR} = SCALAR(0x80fd44c) *main::FH{ARRAY} = ARRAY(0x80fd464) *main::FH{HASH} = HASH(0x80fd4a0) *main::FH{IO} = IO::Handle=IO(0x80fd4dc) foo bar baz quux
$main::FH = 'a string'; print "nope" if not defined *FH{IO}; __output__ nope
_________
broquaint
In reply to Re: typeglob questions
by broquaint
in thread typeglob questions
by princepawn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |