Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7914889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:16:13+00:00 2026-06-03T14:16:13+00:00

Sometime I have to use the bareword STDOUT, sometimes the bareword doesn’t work and

  • 0

Sometime I have to use the bareword “STDOUT”, sometimes the bareword doesn’t work and sometimes I can use the bareword or another form. Are there rules, which tell me when I have to choose on form and when another and when I can choose the form?

#!/usr/bin/env perl
use warnings;
use 5.12.0;
use utf8;


print STDOUT "Something\n";             # works

print \*STDOUT "Something\n";           # String found where operator expected 

print { STDOUT } "Something\n";         # Bareword "STDOUT" not allowed while "strict subs" in use 

print { \*STDOUT } "Something\n"        # works


my $fh;

$fh = -t STDOUT ? STDOUT : STDERR;      # Bareword "STDOUT"/"STDERR" not allowed while "strict subs" in use

$fh = -t STDOUT ? \*STDOUT : \*STDERR;  # works

$fh = -t \*STDOUT ? \*STDOUT : \*STDERR; # works 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:16:15+00:00Added an answer on June 3, 2026 at 2:16 pm

    These are the rules according to my tests:

    1. when use strict subs is in effect, the bareword versions can’t be passed as filehandles, presumably because they could be subroutine calls.

    2. The *STDOUT and \*STDOUT versions can be used to pass to functions all the time.

    3. passing one of them to a sub with foo STDOUT (without parentheses) breaks because perl assumes that is STDOUT->foo.

    4. Aside from cases 1 and 3, you can pass them to subs with the bareword verisons as well.

    5. for calls to print, printf etc, you must either use the bareword versions, or use {}. enclosing the filehandle in {} tells perl that yes the first argument is a filehandle, so you can use any form.

    For these purposes -t counts as a sub, as do other -X tests that accept filehandles.

    When you use {} with print or printf, the part inside {} is a code block; it is evaluated and the result is used as the filehandle. It works with those functions because they are treated specially by perl, in the same way as map and grep.

    So follow these rules and you will be okay:

    • when printing to STDERR or STDOUT explcitly, use the bareword version:

      print STDERR "ERRORRRRR\n";
      
    • when using a filehandle in any other way, use the * version:

      my $isterm = -t *STDOUT;
      close(*STDERR);
      

    I tested as far back as perl 5.8.7. This is as far back as I can go right now. The above should work for 5.6 as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a couple of jobs that use a shared resource (database), which sometimes
I have noticed that sometimes people have to use multiple versions of jQuery in
I have a WCF based service that I use to expose AJAX functionality. Sometimes
I have been using TCPDF for sometime. It's simple to use, outputs low size
I have been using tomcat for sometime and still can't find a good way
I have a source repository for which I use maven. Usually I want to
We have to use 3rd party DLL in our development process, unfortunately we can't
I have a Java EE application which use SQL Server Express as backend database.
When printing a report, the user sometime have the following error: CrystalDecisions.CrystalReports.Engine.LogOnException: Error in
Does Javascript or jQuery have sometime like the in statement in Python? a in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.