Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > globs, ref globs, and lexically scoped filehandles

Reply
Thread Tools

globs, ref globs, and lexically scoped filehandles

 
 
Alex Hart
Guest
Posts: n/a
 
      01-24-2005
2 questions, but somewhat related.

What is the rule for when it's possible to use a glob, and when it's
possible to use a ref glob. Can they always be used interchangably? The
docs seem a little vague on this. Is this a property of the glob, or of
the function being called?

Also, concerning lexically scoped filehandles (which is really a ref
glob, right?), can these be used anywhere a filehandle would be used
(i.e. will they be auto-vivicated anywhere a file handle is expected?).
I always see the example with open, but what about sysopen, or accept,
or bind, or anything else. Can I always use a undefined scalar in these
functions?

Thanks.

- Alex Hart

 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      01-24-2005
Alex Hart <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> 2 questions, but somewhat related.
>
> What is the rule for when it's possible to use a glob, and when it's
> possible to use a ref glob.


The term is "globref", meaning a reference to a glob. "ref glob" doesn't
make sense.

> Can they always be used interchangably? The
> docs seem a little vague on this. Is this a property of the glob, or of
> the function being called?


No, they're not always interchangeable. For one, a globref could be blessed
into any class, and then the class determines its behavior.

Otherwise, the automatic de-referencing of globrefs happens where it is
convenient -- it's a function of the DWIM behavior of Perl. In fact,
even the interpretation of a bare glob as a file handle is a DWIM action.
It might as well be interpreted as something else, or not at all. Since
there is little use for globs in modern Perl, I/O functions take it for
granted that you mean the I/O slot.

> Also, concerning lexically scoped filehandles (which is really a ref
> glob, right?), can these be used anywhere a filehandle would be used
> (i.e. will they be auto-vivicated anywhere a file handle is expected?).
> I always see the example with open, but what about sysopen, or accept,
> or bind, or anything else. Can I always use a undefined scalar in these
> functions?


There is no such thing as lexically scoped filehandles. A lexical variable
can hold a *value* that is interpreted as a filehandle by I/O functions.
This doesn't give the variable special properties of a filehandle, nor
does it make the underlying filehandle "lexical".

As for autovivifivation, I'd expect all methods to open a file handle to
do it. The feature is indeed not described for "sysopen" the way it is for
"open".

Anno
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 5.9 How can I make a filehandle local to a subroutine? How do I pass filehandles between subroutines? How do I make an array of filehandles? PerlFAQ Server Perl Misc 0 01-12-2011 11:00 PM
foreach loops and lexically scoped loop variables Derek Basch Perl Misc 6 05-29-2006 07:44 AM
globs, ref globs, and lexically scoped filehandles Alex Hart Perl Misc 0 01-24-2005 08:21 AM
Lexically scoped variables Eric Sunshine Ruby 6 12-26-2003 10:55 AM
bug in lexically scoped array not reset in foreach loop Gavin Sherlock Perl Misc 1 12-10-2003 10:36 PM



Advertisments