FreeKB - Perl return in a subroutine
Perl - return in a subroutine

If you are not familiar with subroutines, check out our article on Perl - Getting Started with Subroutines.

return will cease execution of a subroutine and return you to your main routine. Take for example the following script. This will print Hello but will not print World, since you are returned before World is printed.

use strict;
use warnings;

sub greeting {
  print "Hello \n";
  print "World \n";



Running this script will output the following.



You can also use return to:


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 4a6b8 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |