PERL Application Type Console Application

 

- Info:

- This tutorial shows how to work with "PERL Console Application".

- Console application uses command line to interact with the user.

 

- Create:

- This example shows how to create and call simple "PERL Console Application".

- Create C:\Temp\Test.pl Start MSDOS cd C:\Temp perl Test.pl

 

Test.pl

print("Hello World!\n");

 

- Input Parameters:

- This example shows how to call "PERL Console Application" with input parameters and read them from the code.

- Create C:\Temp\Test.pl Start MSDOS cd C:\Temp perl Test.pl arg1 arg2 arg3

 

Test.pl

for($i=0;$i<=$#ARGV;$i++) { print("$ARGV[$i]\n"); }

 

- Exit value:

- This example shows how to define exit value of "PERL Console Application".

- This exit value is returned to the application that called Perl script.

- Create C:\Temp\Test.pl and CallMe.pl Start MSDOS cd C:\Temp perl Test.pl

 

Test.pl

system("CallMe.pl");

 

CallMe.pl

exit(20);

 

- Call from Perl Back Ticks:

- This example shows how to call "PERL Console Application" from inside another "PERL Console Application".

- By using back ticks '`' everything that was printed in called Perl script will be returned.

- Back tick is located on the same button where '~' is which is left from number 1 below 'Esc' button.

- Inside back ticks you can use single and double qoutes as you please.

- Create C:\Temp\Test.pl and CallMe.pl Start MSDOS cd C:\Temp perl Test.pl

 

Test.pl

$ret = `CallMe.pl`;

print("Output of CallMe was: $ret"); #Output of CallMe was: Hello from CallMe.pl

 

CallMe.pl

print("Hello from CallMe.pl");

 

- Call from Perl system:

- This example shows how to call "PERL Console Application" from inside another "PERL Console Application".

- In below example function system return 5120 where 20 is return value ps called perl script.

- Number 50 if who knows what and to get rid of it we are shifting the result by 8 bits using >> 8.

- Create C:\Temp\Test.pl and CallMe.pl Start MSDOS cd C:\Temp perl Test.pl

 

Test.pl

$ret = system("CallMe.pl") >> 8;

print($ret); #20.

 

CallMe.pl

exit(20);

 

- Call from Perl exec:

- This example shows how to call "PERL Console Application" from inside another "PERL Console Application".

- Function exec has no return value.

- Create C:\Temp\Test.pl and CallMe.pl Start MSDOS cd C:\Temp perl Test.pl

 

Test.pl

exec("CallMe.pl");

 

CallMe.pl

exit(20);