Variables in PERL - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Variables in PERL

kzuberkzuber Posts: 1Member
This is my code:

sub getDates {

if ($ARGV[0] = "-d") {

print "
-d option
";
$days = $ARGV[1];
$days = 0 unless $days;

$time1 = time;
$time2 = $time1 - 60*60*24*$days;

@return;
$temp;
@lt = localtime($time2);
push @return, [($lt[5]+1900,$lt[4]+1,$lt[3])];

@lt = localtime($time1);
push @return, [($lt[5]+1900,$lt[4]+1,$lt[3])];

return @return;
$beginningdate = @$date1;
print "$beginningdate
";
$enddate = @$date2;
print "$enddate
";

}

else {

print "
argv option
";
$beginningdate = $ARGV[0];
$enddate = $ARGV[1];

}
}

It always chooses the -d option even when argv[0] is not -d. Also, $beginningdate and $enddate is always empty, it never picks up the value from $ARGV[0] and $ARGV[1].

Can anyone tell me why? Thanks.

Comments

  • XfactorXfactor Posts: 343Member
    [b][red]This message was edited by the Xfactor at 2002-4-26 13:11:27[/red][/b][hr]
    : This is my code:
    :
    : sub getDates {
    :
    : if ($ARGV[0] = "-d") {
    :
    : print "
    -d option
    ";
    : $days = $ARGV[1];
    : $days = 0 unless $days;
    :
    : $time1 = time;
    : $time2 = $time1 - 60*60*24*$days;
    :
    : @return;
    : $temp;
    : @lt = localtime($time2);
    : push @return, [($lt[5]+1900,$lt[4]+1,$lt[3])];
    :
    : @lt = localtime($time1);
    : push @return, [($lt[5]+1900,$lt[4]+1,$lt[3])];
    :
    : return @return;
    : $beginningdate = @$date1;
    : print "$beginningdate
    ";
    : $enddate = @$date2;
    : print "$enddate
    ";
    :
    : }
    :
    : else {
    :
    : print "
    argv option
    ";
    : $beginningdate = $ARGV[0];
    : $enddate = $ARGV[1];
    :
    : }
    : }
    :
    : It always chooses the -d option even when argv[0] is not -d. Also, $beginningdate and $enddate is always empty, it never picks up the value from $ARGV[0] and $ARGV[1].
    :
    : Can anyone tell me why? Thanks.
    :
    :

    OK, this line is wrong: if ($ARGV[0] = "-d")
    when you compare strings in perl, you have to use the 'eq' operator.
    That should help.
    Also, in your if (-d) block, once you use a return, anything after that isn't executed in the block. thats why $begindate and $enddate are empty.

    X


Sign In or Register to comment.