Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Can't use string ("main::STDOUT") as a symbol ref while "strict refs" in use

by Anonymous Monk
on Aug 25, 2012 at 15:11 UTC ( #989731=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Eh, HUH!?

$ perl -E " print {select()} 6 " 6 $ perl -Mstrict -le " print {select()} 6 " Can't use string ("main::STDOUT") as a symbol ref while "strict refs" +in use at -e line 1.

/headslap

Comment on Can't use string ("main::STDOUT") as a symbol ref while "strict refs" in use
Download Code
Re: Can't use string ("main::STDOUT") as a symbol ref while "strict refs" in use
by GlitchMr (Sexton) on Aug 25, 2012 at 18:27 UTC

    select returns currently selected filehandle. Until you will select other filehandle, it's main::STDOUT. Because it's bareword filehandle, it's returned as string. When printing to it, print notices it's string and strict 'refs' is enabled, so it dies.

    Instead, you can try workaround of using IO::Handle method. With Perl older than 5.14, you have to use IO::Handle - it's optional is Perl 5.14.

    select->print(6)
Re: Can't use string ("main::STDOUT") as a symbol ref while "strict refs" in use
by Mr. Muskrat (Abbot) on Aug 26, 2012 at 17:50 UTC

    GlitchMr is correct however there is another way (this is Perl after all... TIMTOWTDI). Just disable strict refs.

    perl -Mstrict -M-strict=refs -e "print {select()} 6" 6

    Long version:

    use strict; no strict 'refs' print {select()} 6;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://989731]
Approved by Corion
Front-paged by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-12-20 15:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (96 votes), past polls