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.

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

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

greeting();

 

Running this script will output the following.

Hello

 

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.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |