Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.