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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:59:12+00:00 2026-06-05T17:59:12+00:00

Exact error: $ ./script.pl file.txt Can’t open file.txt: No such file or directory at

  • 0

Exact error:

$ ./script.pl file.txt  
Can't open file.txt: No such file or directory at ./script.pl line 17. 
Use of uninitialized value in chomp at ./script.pl line 17. 
Username: Password:

I’m writing a script that takes a filename from the commandline and then writes its output to it:

#!/usr/bin/perl
use warnings;
use strict;
use Term::ReadKey;

my @array;
my $user;
my $pass;

# get login info
print "Username: ";
chomp($user = <>); # line 17
print "Password: ";
ReadMode 2;
chomp($pass = <>);
ReadMode 0;
print " \n";

# ...
# connect to database, and save the info in "@array" 
# ...

# save the array to a file
if (defined($ARGV[0])) {
    open (MYFILE, ">".$ARGV[0]) or die "Can't open ".$ARGV[0].": $!\n";
    foreach (@array) {
        print MYFILE $_."\n";
    }
    close (MYFILE);
# otherwise, print the names to the screen
} else {
    foreach (@array) {
        print $_."\n";
    }
}

However if I replace ARGV[0] with "file.txt" or something similar, printing to the file works fine. If I do not provide a filename, the script works fine. My hunch is that the print statement is interfering with the iostream buffer but I can’t figure out how to fix it.

  • 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-05T17:59:14+00:00Added an answer on June 5, 2026 at 5:59 pm

    That is how the magic diamond operator works in Perl. If you start the script with an argument, it tries to read input from the file. If you feed it a standard input, it reads from there.

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

Sidebar

Related Questions

I'm trying to execute an EXE file using a PowerShell script. If I use
The exact error I am getting in Visual Studio 2012 is: error BC30456: 'Dispose'
The applicable code is below, as is the exact error. sd = socket(AF_INET, SOCK_RAW,
I'm getting a bunch of failing tests (21 to be exact)/ an error message
Exact duplicate: .Net Parse versus Convert can anyone help me?
I've got a command line script that is running an array() of files through
I have 2 methods within a rake script, both of which use system <SomeCommand>
I'm trying to debug a shell script that calls an awk file. Which is
..of which I can't figure out what the exact problem is and/or why the
I am trying to read a file in the same directory as the Perl

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.