Thursday, November 6, 2008

PERL - IF ELSE statement shortcuts

I will give an example of how to write IF ELSE statement in short. This will be simply useful to read others code if you know that this can also be an option. This kind of code normally comes from seasoned PERL programers.


use warnings;
use strict;

print &max(5, 3);
print &max(7, 10);

sub max (@)
my ($x, $y) = @_;
return $x > $y ? $x : $y;

Explanation: In function max, 2nd lines means that

if $x is greater than $y, return $x or return $y. That's it.....

No comments: