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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:30:08+00:00 2026-05-19T02:30:08+00:00

what is the best way to break out of a subroutine & continue processing

  • 0

what is the best way to break out of a subroutine & continue processing the rest of the script?

ie

#!/usr/bin/perl
use strict;
use warnings;

&mySub;

print "we executed the sub partway through & continued w/ the rest 
of the script...yipee!\n";

sub mySub{

    print "entered sub\n";

    #### Options
    #exit; # will kill the script...we don't want to use exit
    #next; # perldoc says not to use this to breakout of a sub
    #last; # perldoc says not to use this to breakout of a sub
    #any other options????

    print "we should NOT see this\n";

}
  • 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-05-19T02:30:09+00:00Added an answer on May 19, 2026 at 2:30 am

    At the expense of stating the obvious the best way of returning for a subroutine is ……

    return
    

    Unless there is some hidden subtlety in the question that isn’t made clear

    Edit – maybe I see what you are getting at

    If you write a loop, then a valid way of getting out of the loop is to use last

        use strict ;
        use warnings ;
        while (<>) {
           last if /getout/ ;
           do_something() ;
        }
    

    If you refactor this, you might end up with a using last to get out of the subroutine.

        use strict ;
        use warnings ;
        while (<>) {
           process_line() ;
           do_something() ;
        }
    
        sub process_line {
           last if /getout/ ;
           print "continuing \n" ;
        }
    

    This means you are using last where you should be using return and if you have wanings in place you get the error :

    Exiting subroutine via last at ..... some file ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the best way to break from nested loops in Javascript? //Write the links
What is the best way to exit out of a loop as close to
I'm trying to figure out the best way to search a customer in an
I'm trying to figure out the best way to save (serialize) and later open
What is the best way to verify/test that a text string is serialized to
What is the best way of creating an alphabetically sorted list in Python?
What is the best way to authorize all users to one single page in
What is the best way to store international addresses in a database? Answer in
What is the best way to include an html entity in XSLT? <xsl:template match=/a/node>
What is the best way to iterate through a strongly-typed generic List in C#.NET

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.