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 730457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:54:50+00:00 2026-05-14T06:54:50+00:00

I am having some trouble trying to print from a file. Any ideas? Thanks

  • 0

I am having some trouble trying to print from a file. Any ideas? Thanks

open(STDOUT,">/home/int420_101a05/shttpd/htdocs/receipt.html"); 
#Results of a sub-routine
&printReceipt; 
close(STDOUT);

open(INF,"/home/int420_101a05/shttpd/htdocs/receipt.html"); $emailBody = <INF>; 
close(INF); 
print $emailBody;

ERRORS: Filehandle STDOUT reopened as INF only for input at ./test.c line 6. 
print() on closed filehandle STDOUT at ./test.c line 9.
  • 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-05-14T06:54:50+00:00Added an answer on May 14, 2026 at 6:54 am
    1. This discussion addresses the technical reason for the message. Relevant info from the thread is this:

      From open(2) manpage:

      When the call is successful, the file descriptor returned will be
      the lowest file descriptor not currently open for the process.

      But STDOUT still refers to the
      filehandle #1. This warning could be
      useful. Although one can argue that
      further uses of STDOUT as an output
      filehandle will trigger a warning as
      well…

      So, to summarize, you closed STDOUT (file descriptor 1) and your file will be open as FD#1. That’s due to open()'s properties.

    2. As other have noted, the real reason you’re having this problem is that you should not use STDOUT for printing to a file unless there’s some special case where it’s required.

      Instead, open a file for writing using a new file handle:

      open(OUTFILE,">/home/int420_101a05/shttpd/htdocs/receipt.html")
         || die "Could not open: $!"; 
      print OUTFILE "data";
      close(OUTFILE);
      
    3. To print to filehandle from subroutine, just pass the file handle as a parameter.

      The best way of doing so is to create an IO::File object and pass that object around

      my $filehandle = IO::File->new(">$filename") || die "error: $!";
      mySub($filehandle);
      
      sub mySub {
       my $fh = shift;
       print $fh "stuff" || die "could not print $!";    
      }
      

      You can also set a particular filehandle as a default filehandle to have print print to that by default using select but that is a LOT more fragile and should be avoidded in favor of IO::File solution.

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

Sidebar

Related Questions

I am having some trouble trying to get a report to print from a
I'm having some trouble trying to incorporate a read and write statement into evaluateStatementInner
I am having some trouble trying to figure out, how to accomplish the following.
I am having some trouble trying to adjust the deployment settings of our application
I'm having some trouble trying running a function only once when onresize event is
I am having some trouble trying to figure out how to parse information collected
I am having some trouble trying to checkout the BitSharp source code using SVN.
I'm trying to work with the google maps API and am having some trouble.
I'm trying to utilize Boost.Test in Visual Studio 2010, and I'm having some trouble
I'm trying to track some goals via regex and I'm having trouble getting them

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.