IF-THEN-ELSE in PERL not working

Guys,
i was trying a simple if-then-else statement in perl; but not getting any success in that.
can you please help, where i am wrong. I tried $diff variable with double quotes as well, but no go.

$region = $ARGV[0];
$diff = $ARGV[1];

if [ $diff -eq 1 ]; then
        ($date) = split(' ', `ssh -xC $san[0] cat /tmp/prev_biz_date`);
else
        ($date) = split(' ', `ssh -xC $san[0] cat tmp/current_date`);
fi

Getting the below compilation error

sandos% /tmp/newXmit1 UT 1
syntax error at /tmp/newXmit1 line 20, near "if ["
syntax error at /tmp/newXmit1 line 22, near "else"
Execution of /tmp/newXmit1 aborted due to compilation errors.

When tried with "$diff"

$region = $ARGV[0];
$diff = $ARGV[1];

if [ "${diff}" -eq 1 ]; then
        ($date) = split(' ', `ssh -xC $san[0] cat /tmp/prev_biz_date`);
else
        ($date) = split(' ', `ssh -xC $san[0] cat tmp/current_date`);
fi

print "DIST FOR $date\n";

Compilation error is as below

sandosk% /tmp/newXmit1 UT 1
syntax error at /tmp/newXmit1 line 20, near "if ["
Execution of /tmp/newXmit1 aborted due to compilation errors.

Hi

You are using the shell syntax of if.

Perl syntax:

if ($diff == 1 ) {
   .....
}else {
   .......
}

Guru.

1 Like

Thank you guru :slight_smile: