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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:24:39+00:00 2026-06-09T10:24:39+00:00

I have code which stores all the files handles for files in the current

  • 0

I have code which stores all the files handles for files in the current directory as values in a hash. The keys are the names of the files.

my %files_list;    #this is a global variable.
sub create_hash() {
    opendir my $dir, "." or die "Cannot open directory: $!";
    my @files = readdir $dir;
    foreach (@files) {
        if (/.text/) {
            open(PLOT, ">>$_") || die("This file will not open!");
            $files_list{$_} = *PLOT;
        }
    }
}

Down the line I am using print statements in my code where I am facing some compilation issues.

my $domain = $_;
opendir my $dir, "." or die "Cannot open directory: $!";
my @files = readdir $dir;
foreach (@files) {
    if (/.text/ && /$subnetwork2/) {
        print $files_list{$_} "$domain";    #this is line 72 where there is error.
    }
}
closedir $dir;

The compilation errors are below:

String found where operator expected at process.pl line 72, near "} "$domain""
        (Missing operator before  "$domain"?)
syntax error at process.pl line 72, near "} "$domain""

Could anyone please help me understand the fault?

  • 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-09T10:24:40+00:00Added an answer on June 9, 2026 at 10:24 am

    first problem:
    After running create_hash subroutine you would have %files_list filled up with *PLOT in all keys.

    all print {$files_list{$_}} "$domain"; whould print into last opened file.
    solution:

    -open(PLOT,">>$_") || die("This file will not open!");
    -$files_list{$_}=*PLOT;
    +open($files_list{$_},">>$_") || die("This file will not open!");
    

    second problem:
    you don’t check that file descriptor exists before printing into it
    solution:

    -if(/.text/ && /$subnetwork2/)
    -{
    -    print $files_list{$_} "$domain";#this is line 72 where there is error.
    +if(/.text/ && /$subnetwork2/ && exists $files_list{$_})
    +{
    +    print {$files_list{$_}} $domain;
    

    and don’t forget about closing file handles…

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

Sidebar

Related Questions

I currently have this code which stores XML into an XML-type column called data,
I have some PHP code which stores whatever is typed in a textbox in
I have code which needs to do something like this There is a list
I have code which as been working against an older Active Directory server and
I have code which works in all sorts of different situations, including when copying
I currently have PHP code that handles the logic for this because I do
I have code which has a drop down list. And when a certain option
I have code which looks like: private static DirectiveNode CreateInstance(Type nodeType, DirectiveInfo info) {
I have code which performs query on Jboss server. It has JNDI based datasource
I already have code which lazy loads scripts on request. My issue now is

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.