Cannot get the Dialstatus

Hi Everyone!

I have perl AGI, and trying to get the dialstatus after the dial command but unable to get the status in any form.

$AGI->exec(‘Dial’,“SIP/$name,40r”);
my $dialstatus = $AGI->get_variable(“DIALSTATUS”);
$AGI->verbose(“DIALSTATUS IS : $dialstatus”);

But SOMETIMES when I place multiple commands of $dialstatus = $AGI->get_variable(“DIALSTATUS”);
it gives the actul value. Also tried putting WAIT() before getting dialstatus but it dint helped.