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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:03:26+00:00 2026-06-04T08:03:26+00:00

I want the user to input a file name and have the program output

  • 0

I want the user to input a file name and have the program output the contents of the file.

I get 2x “Unquoted string may clash with future reserved word” and “Global symbol $filename requires explicit package name.

use strict;
use warnings;
print 'Enter file name: ';
my $fileName = <STDIN>;
chomp($fileName);
open(fh, $filename or die $!);

Also, why is file handle not a variable (actually depending on the example I’ve seen it a variable or not, like what I have here)?

  • 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-04T08:03:28+00:00Added an answer on June 4, 2026 at 8:03 am

    All your problems are right here (and $filename vs. $fileName).

    open(fh, $filename or die $!);
    

    You want something more like

    open (my $fh, '<', $filename) || die $!;
    

    In the first case, the die condition is on $filename; it’s equivalent to:

    if (!$filename) { die $! }
    

    But the second one is more like:

    if (!open (my $fh, '<', $filename)) { die $! }
    

    Although doing it this way (with if (!open)) is pointless unless you declare $fh with a more useful scope — right now it’s only visible inside the if block.

    The second case implicitly covers the first case, since if $filename is undefined open() will fail with Use of uninitialized value $filename in open.

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

Sidebar

Related Questions

I have a textbox where i want to read user-input mathematical functions( ex: Math.Sqrt(x)
I have html form and I want to add validation on user input -
I have several scripts that take as input a directory name, and my program
Okay, so ultimately I want a program where the user can input simple data
I've written a small assember program that gets and input file, an output file
I have a problem in PHP. I am using <input type=file> to get the
The user should input some file names in the command line and the program
I have an upload field and I want to read user input with jquery
I have a Xml file:- <Users> <User Name=abc Pass=asp></User> <User Name=def Pass=net></User> </Users> I
please help me: I want the user to enter a file name containing numbers

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.