What do I gain if I write to a real reference like \*STDOUT instead of a typeglob like *STDOUT?
What do I gain if I write to a real reference like \*STDOUT instead
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One is a typeglob, another is a reference to it.
As far as I know, the main practical difference is that you can NOT bless a typeglob into an object, but you CAN bless the typeglob reference (which is what
IO::Handledoes)This distinction is discussed in detail in “Perl Cookbook”, Recipe 7.16. “Storing Filehandles in Variable”.
Another difference is that assigning a glob creates an alias to the ENTIRE glob, whereas assigning a glob reference does the expected (as discussed in
perldoc perlmod, "Symbol Tables" section. To illustrate:Produces:
As a side note, a rumor that the typeglob reference is the only way to pass the filehandle into a function is not the case: