Bootstrap FreeKB - Perl (Scripting) - return a string
Perl (Scripting) - return a string

Updated:   |  Perl (Scripting) articles

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

Let's say you have the following script. In this example, the greeting subroutine will return string "Hello World".

sub greeting {
  return "Hello World";
}

 

Outside of the subroutine, the output of the greeting subroutine is stored in the $foo variable.

my $foo = greeting();

 

You could then print the $foo variable.

print "$foo \n";

 

Which would return the following.

Hello World

 

Likewise, you could store the output of the greeting subroutine in an array.




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


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