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

  • Home
  • SEARCH
  • 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 8877823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:33:42+00:00 2026-06-14T19:33:42+00:00

I want to check for a condition, print a warning, and return from a

  • 0

I want to check for a condition, print a warning, and return from a subroutine with a single line of code. This works (and I think warn returns 1):

return warn "can't find file" if not -f $input_file;

Can I do this safely? Or is there a better way to go?

  • 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-14T19:33:44+00:00Added an answer on June 14, 2026 at 7:33 pm

    That’s perfectly safe, but it requires looking at the source to determine what value is returned (true), and it leaves no readable option to control what value gets returned. This is rather important because you’d normally want to return nothing/undef/false in this situation, but you’re currently returning true.

    All of the following alternatives allow you to specify the value returned:

    warn("can't find file"), return if !-f $input_file;
    
    (warn "can't find file"), return if !-f $input_file;
    
    if (!-f $input_file) { warn "can't find file"; return }
    
    -f $input_file or warn("can't find file"), return;
    
    -f $input_file or (warn "can't find file"), return;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to check an array in a condition. Let's take this simple code
I want to check checkbox like $('#riderCheck').attr('checked','true') on some condition. but the problem is
I have a vairable DECLARE @AssignOn nvarchar(20)='0,2,5' I want to check a condition like
I have a method. I want to check a condition and if result of
in if condition i want to check if(isset($_GET['q'])) { echo ok; } esle {
This program want to read from a file. the content in the file is
I want to remove all my debugging printf statements from my code .How can
I don't want check if an item with a value exists in the arraylist,
I want to check which port is used, when the port is not explicitly
I want to check if my many column in datagridview is empty. here my

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.