0

I am processing time and need to input certain values into equations that are based on difference between UTC and Local Standard time. So, for Los Angeles the @ARGV input would be "8" and the value needed to be inserted into the nest equation would be "4" but the script won't select the appropriate value. Instead, it only selects the first value in the process despite the fact that the ARGV value is not five. What am I doing wrong?

$std_time = (@ARGV[0]);
    if ($std_time = 5) {(std_time_pro = 7);}
    elsif ($std_time = 6) {(std_time_pro = 6);}
    elsif ($std_time = 7) {(std_time_pro = 5);}
    elsif ($std_time = 8) {(std_time_pro = 4);}
    elsif ($std_time = 9) {(std_time_pro = 3);}
    elsif ($std_time = 10) {(std_time_pro = 2);}

$shft_number = (($std_time_pro * 3600) / 86400);
AtmoSci
  • 87
  • 1
  • 1
  • 7
  • 1
    What you have posted isn't Perl code and won't compile. Please copy and paste the real code that is giving you a problem – Borodin Jul 17 '14 at 21:39

3 Answers3

6

Use == to test for numeric equality, not the assignment operator =.

Additionally, I suspect a reminder to always include use strict and use warnings at the top of EVERY Perl script. For some of the many reasons why, just read: Why use strict and warnings?

Finally, instead of a list of if statements, I would recommend building a hash to relate your two values:

use strict;
use warnings;

my ($std_time) = @ARGV;

my %std_time2pro = map {$_ => 12 - $_} (5..10);

my $std_time_pro = $std_time2pro{$std_time} // die "Invalid value of std_time: $std_time";
Community
  • 1
  • 1
Miller
  • 34,962
  • 4
  • 39
  • 60
1

You need to change = to == to test equality;

salparadise
  • 5,699
  • 1
  • 26
  • 32
1

Not only do you need to change the = to ==, it looks like you are assigning values to std_time_pro instead of $std_time_pro.

You need to always have these two lines at the top of every Perl program you write to catch problems like these:

use warnings;
use strict;
Andy Lester
  • 91,102
  • 13
  • 100
  • 152