Search This Blog

Tuesday, March 8, 2011

PERL: SHORTCTUS


  1. <STDIN> Command is used to scan the inputs.
    Ex:
$a=<STDIN>;

You can shorten this command as shown below,
$a=<>;

2. Consider an example,
print “Enter a number \n”;
$a=<STDIN>;
if($a=1)
{
print “..............................\n”;
}

You can shorten the above script as shown below,
print “Enter a number \n”;
if(<>=1)
{
print “..............................\n”;
}
No need to save the scanned inputs in a variable, You can compare the scanned inputs directly.

3.Use EOT command to print multiple lines.
Ex:

print << 'EOT';
ENTER 1 for .....................
ENTER 2 for .....................
ENTER 3 for .....................
ENTER 4 for .....................
EOT