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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:31:52+00:00 2026-06-03T06:31:52+00:00

This construct is pretty common in perl: opendir (B,/somedir) or die couldn’t open dir!;

  • 0

This construct is pretty common in perl:

opendir (B,"/somedir") or die "couldn't open dir!";

But this does not seem to work:

opendir ( B, "/does-not-exist " ) or {
    print "sorry, that directory doesn't exist.\n";
    print "now I eat fugu.\n";
    exit 1;
};

Is it possible for the “or” error-handling to have more than one command?

Compiling the above:

# perl -c test.pl
syntax error at test.pl line 5, near "print"
syntax error at test.pl line 7, near "}"
test.pl had compilation errors.
  • 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-03T06:31:53+00:00Added an answer on June 3, 2026 at 6:31 am

    You can always use do:

    opendir ( B, "/does-not-exist " ) or do {
        print "sorry, that directory doesn't exist.\n";
        print "now I eat fugu.\n";
        exit 1;
    }
    

    Or you can use if/unless:

    unless (opendir ( B, "/does-not-exist " )) {
        print "sorry, that directory doesn't exist.\n";
        print "now I eat fugu.\n";
        exit 1;
    }
    

    Or you can swing together your own subroutine:

    opendir ( B, "/does-not-exist " ) or fugu();
    
    sub fugu {
        print "sorry, that directory doesn't exist.\n";
        print "now I eat fugu.\n";
        exit 1;
    }
    

    There is more than one way to do it.

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

Sidebar

Related Questions

I have a feeling that this query is pretty easy to construct, I just
This is a simple question but I don't know how to construct a variable
Ok at this point, I am pretty confused on how to construct my pagination
Does anyone know what causes the following errors? This seems like a pretty standard
This should be pretty trivial but for whatever reason, I'm having a little trouble
(This is probably a duplicate, but I could not find it - feel free
This is a pretty basic question but I'm still unsure: If I have a
I'm pretty sure this is a duplicate question, but I can't find the original(s).
This may sound trivial, but I'm pretty sure this question hasn't been asked, or
This is a pretty minor issue but it's bugging me - I am trying

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.