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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:37:16+00:00 2026-05-15T12:37:16+00:00

please look at the following code first. #! /usr/bin/perl package foo; sub new {

  • 0

please look at the following code first.

#! /usr/bin/perl
package foo;

sub new {

    my $pkg = shift;
    my $self = {};
    my $self->{_fd} = undef;
    bless $self, $pkg;

    return $self;
}

sub Setfd {

    my $self = shift;
    my $fd = shift;
    $self_->{_fd} = $fd;
}

sub write {

    my $self = shift;
    print $self->{_fd} "hello word";
}

my $foo = new foo;

My intention is to store a file handle within a class using hash. the file handle is undefined at first, but can be initilized afterwards by calling Setfd function. then
write can be called to actually write string “hello word” to a file indicated by the file handle, supposed that the file handle is the result of a success “write” open.

but, perl compiler just complains that there are syntax error in the “print” line. can anyone of you tells me what’s wrong here? thanks in advance.

  • 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-15T12:37:16+00:00Added an answer on May 15, 2026 at 12:37 pm

    You will need to put the $self->{_fd} expression in a block or assign it to a simpler expression:

        print { $self->{_fd} } "hello word";
    
        my $fd = $self->{_fd};
        print $fd "hello word";
    

    From perldoc -f print:

    Note that if you’re storing FILEHANDLEs in an array, or if you’re using any other expression more complex than a scalar variable to retrieve it, you will have to use a block returning the filehandle value instead:

    print { $files[$i] } "stuff\n";
    print { $OK ? STDOUT : STDERR } "stuff\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 510k
  • Answers 510k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use connectivitymanager for this.ConnectivityManager cm = (ConnectivityManager)Context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo… May 16, 2026 at 4:58 pm
  • Editorial Team
    Editorial Team added an answer The easy solution is to simply kill and restart the… May 16, 2026 at 4:58 pm
  • Editorial Team
    Editorial Team added an answer You must OR the OPENFILENAME flags with |, not || May 16, 2026 at 4:58 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

First of all have a look at the following code (in this code shape
please take a look at the following website: http://www.solidcamxpress.co.uk/ If you look at it
I am using following code to start activity when user pressing search button on
Please look at my sourcecode. public class EntityQuery { public static Func<AdventureWork2008Container, IQueryable<SalesPerson>> selectQuery
I have a question regarding the following code: abstract class a { public static
Inorder to split the string i have used the following code. $string = -sev*yes-sev1*no-sev2*yes;
I've been looking through a piece of code of a pc game that I'm
Please remember that I am not using any ORM tool. I have just written
I have a new earthquake notification android app thats in it's initial release version.
I have following string: <div> text0 </div> prefix <div> text1 <strong>text2</strong> text3 </div> text4

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.