Reputation: 491
I get a couple of syntax errors when trying to use an if-statement.
This is my code:
use warnings;
use LWP::Simple;
use POSIX;
my $dtime = strftime('%Y-%m-%d %H:%M:%S', gmtime(1593953411))
if ($dtime->day_of_week == 7 || $dtime->day_of_week == 6){
$total_between_time = $total_between_time - $dayinsec
}
else{
if (($time1+($i*$dayinsec)) + $dayinsec > $time2){
print "beggining: ", $time1+$i*$dayinsec, " end: ", $time2, "\n";
}
else{
print "beggining: ", $time1+$i*$dayinsec, " end: ", ($time1+($i*$dayinsec)) + $dayinsec, "\n";
}
}
I'm getting the following errors:
syntax error at ovning2.pl line 30, near "){"
syntax error at ovning2.pl line 33, near "else"
Why am I getting these errors?
Upvotes: 1
Views: 357
Reputation: 132783
You don't have 33 lines in your sample code, so those errors are from something else.
When you get errors, remember that the error is from the point that Perl got confused. The error has already happened. Look at the line before the error number:
When you can't track down these problems, start bisecting your code. You may start with this, and see that it works:
use warnings;
use LWP::Simple;
use POSIX;
my $dtime = strftime('%Y-%m-%d %H:%M:%S', gmtime(1593953411))
__END__
... rest of program
Then, add a little more, and you discover an error. Now you have a target to investigate:
...
my $dtime = strftime('%Y-%m-%d %H:%M:%S', gmtime(1593953411))
if ($dtime->day_of_week == 7 || $dtime->day_of_week == 6){
$total_between_time = $total_between_time - $dayinsec
}
__END__
Maybe you still don't see it, so play with that little bit:
...
my $dtime = strftime('%Y-%m-%d %H:%M:%S', gmtime(1593953411))
if (1){1}
__END__
Continue in this manner so in each step you convince yourself that something is not the problem.
Upvotes: 1
Reputation: 3222
Problem is not with if
condition.
There is a semicolon missing in my $dtime = strftime('%Y-%m-%d %H:%M:%S', gmtime(1593953411))
line.
Upvotes: 2
Reputation: 62037
You are missing a semicolon at the end of the line before your if
statement. Fixed:
my $dtime = strftime('%Y-%m-%d %H:%M:%S', gmtime(1593953411));
Upvotes: 3