Returning from Perl File

I had a situation where I had to return some data from a Perl file. Not from a perl function but from the file itself to a shell script from where I was calling the Perl file.

The way to return from this is to write to the standard output.

This is how we do it:

Perl File HelloWorld.pl:

open (OUT, '>-');

This opens the standard output for writing

print OUT "Hello World"

Shell script:

RETVAL=`perl HelloWorld.pl`

echo $RETVAL;