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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:53:38+00:00 2026-05-10T16:53:38+00:00

I have a subroutine that takes a filehandle as an argument. How do I

  • 0

I have a subroutine that takes a filehandle as an argument. How do I make a filehandle from a file path specified on the command line? I don’t want to do any processing of this file myself, I just want to pass it off to this other subroutine, which returns an array of hashes with all the parsed data from the file.

Here’s what the command line input I’m using looks like:

$ ./getfile.pl /path/to/some/file.csv

Here’s what the beginning of the subroutine I’m calling looks like:

sub parse {     my $handle = shift;     my @data   = <$handle>;     while (my $line = shift(@data)) {       # do stuff     } } 
  • 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. 2026-05-10T16:53:39+00:00Added an answer on May 10, 2026 at 4:53 pm

    Command line arguments are available in the predefined @ARGV array. You can get the file name from there and use open to open a filehandle to it. Assuming that you want read-only access to the file, you would do it this way:

    my $file = shift @ARGV; open(my $fh, '<', $file) or die 'Can't read file '$file' [$!]\n'; parse($fh); 

    Note that the or die... checks the call open for success and dies with an error message if it wasn’t. The built-in variable $! will contain the (OS dependent) error message on failure that tells you why the call wasn’t successful. e.g. ‘Permission denied.’

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

Sidebar

Ask A Question

Stats

  • Questions 286k
  • Answers 286k
  • 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 I found the solution. This plugin doesn't work with IE… May 13, 2026 at 4:50 pm
  • Editorial Team
    Editorial Team added an answer The iPhone does not support all streaming video formats. You… May 13, 2026 at 4:50 pm
  • Editorial Team
    Editorial Team added an answer Remove the void. Constructors have no return type. May 13, 2026 at 4:50 pm

Related Questions

I have a data set which is a large unweighted cyclic graph The cycles
Related: How to list the elements of the path in a batch file? How
I am using a microcontroller with a C51 core. I have a fairly timeconsuming
I have some code which uses recursion in its implementation. The profiler which I'm

Trending Tags

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

Top Members

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.