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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:48:14+00:00 2026-06-02T22:48:14+00:00

Why does this script continue to run and not die, when I pass an

  • 0

Why does this script continue to run and not die, when I pass an invalid file-name?

#!/usr/bin/env perl
use warnings;
use 5.12.0;
use Getopt::Long qw(GetOptions :config bundling);

sub help {
    say "no help text";
}

sub read_config {
    my $file = shift;
    open my $fh, '<', $file or die $!;
    say <$fh>;
    close $fh;
}

sub helpers_dispatch_table {
    return {
        'h_help'                => \&help,
        'r_read'                => \&read_config,
    };
}

my $file_conf = 'does_not_exist.txt';
my $helpers = helpers_dispatch_table();

GetOptions (
    'h|help'            => sub { $helpers->{h_help}(); exit; },
    'r|read'            => sub { $helpers->{r_read}( $file_conf ); exit },
);

say "Hello, World!\n" x 5;
  • 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-02T22:48:15+00:00Added an answer on June 2, 2026 at 10:48 pm

    From perldoc Getopt::Long

       A trivial application of this mechanism is to implement options that are related to each other. For example:
    
           my $verbose = '';   # option variable with default value (false)
           GetOptions ('verbose' => \$verbose,
                       'quiet'   => sub { $verbose = 0 });
    
       Here "--verbose" and "--quiet" control the same variable $verbose, but with opposite values.
    
       If the subroutine needs to signal an error, it should call die() with the desired error message as its argument. GetOptions() will catch the die(),
       issue the error message, and record that an error result must be returned upon completion.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a Bash shell script that does something like this: #!/bin/bash
Does anyone know if this script will continue to have a future or is
Why does this script return a pair of nulls? I'm using SQL Server 2008,
I could use another pair of eyes. This script does what I want in
I have to write a Matlab script that does this: The input is 2
EDIT: It does work (sorry). Something in this script is causing it to stop
I have a simple script that does some search and replace. This is basically
I have been working on this for some time. The script does work and
This is not a new problem for me. From C to PERL to Python
git rebase does not appear to work properly in certain cases where a file

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.