Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运输手续费CGI/Perl_Perl_Cgi_Shipping - Fatal编程技术网

运输手续费CGI/Perl

运输手续费CGI/Perl,perl,cgi,shipping,Perl,Cgi,Shipping,我想为阿拉斯加(AK)和夏威夷(HI)加上25美元的固定手续费——当我将州和固定手续费添加到下面的运输矩阵中时,我的测试中断。有人能给我指出正确的方向吗 my $totalPounds = sprintf("%.2f",($totalWeight / 16)); #my $shipping = &getShipUPS($totalPounds, $zip, $shipType); if ($subtotal <= 24.99) {$shipping = '10.95';} elsi

我想为阿拉斯加(AK)和夏威夷(HI)加上25美元的固定手续费——当我将州和固定手续费添加到下面的运输矩阵中时,我的测试中断。有人能给我指出正确的方向吗

my $totalPounds = sprintf("%.2f",($totalWeight / 16));
#my $shipping = &getShipUPS($totalPounds, $zip, $shipType);
if ($subtotal <= 24.99) {$shipping = '10.95';}
elsif (($subtotal > 24.99) && ($subtotal <= 74.99)) {$shipping = '13.95';}
elsif (($subtotal > 74.99) && ($subtotal <= 149.99)) {$shipping = '14.95';}
elsif ($subtotal >= $150) {$shipping = '18.95';}
elsif ($state eq 'HI','AK') ($subtotal <= 24.99) {$shipping = '10.95'+'25.00';}
elsif ($state eq 'HI','AK') (($subtotal > 24.99) && ($subtotal <= 74.99)) {$shipping = '13.95'+'25.00';}
elsif ($state eq 'HI','AK') (($subtotal > 74.99) && ($subtotal <= 149.99)) {$shipping = '14.95'+'25.00';}
elsif ($state eq 'HI','AK') ($subtotal >= $150) {$shipping = '18.95'+'25.00';}else 

$shipping = sprintf("%.2f", $shipping);

my $total = $subtotal + $tax + $shipping;
$subtotal = sprintf("%.2f", $subtotal);
$total = sprintf("%.2f", $total);
my$totalPounds=sprintf(%.2f),($totalWeight/16));
#my$shipping=&getshippup($totalPounds,$zip,$shipptype);
如果($subtotal 24.99)&&($subtotal 74.99)&($subtotal=$150){$shipping='18.95';}
elsif($eq'HI','AK')($subtotal 24.99)&($subtotal 74.99)&($subtotal=$150){$shipping='18.95'+'25.00';}其他
$shipping=sprintf(“%.2f”,$shipping);
我的$total=$subtotal+$tax+$shipping;
$subtotal=sprintf(“%.2f”,小计$subtotal);
$total=sprintf(“%.2f”,合计$total);

您不能像这样对
eq
使用多个参数

$state eq 'HI','AK'
elsif ($state eq 'HI','AK') ($subtotal >= $150) 
你需要做什么

$state eq 'HI' or $state eq 'AK'
elsif ( ($state eq 'HI' or $state eq 'AK') or ($subtotal >= $150) )
#     ^----               main parantheses                 -------^
此外,您不能像这样在
elsif
之后的第一个括号后面加上另一个括号

$state eq 'HI','AK'
elsif ($state eq 'HI','AK') ($subtotal >= $150) 
你需要做什么

$state eq 'HI' or $state eq 'AK'
elsif ( ($state eq 'HI' or $state eq 'AK') or ($subtotal >= $150) )
#     ^----               main parantheses                 -------^
当然,更明智的选择可能是使用散列

%extra_charges = ( AK => 25, 
                   HI => 25,
                   # etc
);
...
$subtotal += $extra_charges{$state};   # assuming no missing states
if-else逻辑也是各种冗余的。这应该相当于您的代码:

if    ($subtotal <= 24.99)            { $shipping = '10.95' }
elsif ($subtotal <= 74.99)            { $shipping = '13.95' }
elsif ($subtotal <= 149.99)           { $shipping = '14.95' }
else                                  { $shipping = '18.95' }

if ($state eq 'AK' or $state eq 'HI') { $shipping += 25 }

if($subtotal您不能像这样对
eq
使用多个参数

$state eq 'HI','AK'
elsif ($state eq 'HI','AK') ($subtotal >= $150) 
你需要做什么

$state eq 'HI' or $state eq 'AK'
elsif ( ($state eq 'HI' or $state eq 'AK') or ($subtotal >= $150) )
#     ^----               main parantheses                 -------^
此外,您不能像这样在
elsif
之后的第一个括号后面加上另一个括号

$state eq 'HI','AK'
elsif ($state eq 'HI','AK') ($subtotal >= $150) 
你需要做什么

$state eq 'HI' or $state eq 'AK'
elsif ( ($state eq 'HI' or $state eq 'AK') or ($subtotal >= $150) )
#     ^----               main parantheses                 -------^
当然,更明智的选择可能是使用散列

%extra_charges = ( AK => 25, 
                   HI => 25,
                   # etc
);
...
$subtotal += $extra_charges{$state};   # assuming no missing states
if-else逻辑也是各种冗余的。这应该与您的代码等效:

if    ($subtotal <= 24.99)            { $shipping = '10.95' }
elsif ($subtotal <= 74.99)            { $shipping = '13.95' }
elsif ($subtotal <= 149.99)           { $shipping = '14.95' }
else                                  { $shipping = '18.95' }

if ($state eq 'AK' or $state eq 'HI') { $shipping += 25 }

if($subtotal这段代码乱七八糟,有多个语法错误,而且违反了DRY

最好先计算基本运费,具体取决于小计。第二步,如果所在州是夏威夷或阿拉斯加,则添加25美元的费用:

my @shipping_fees = (
  # max subtotal => fee
  [  24.99 => 10.95 ],
  [  74.99 => 13.95 ],
  [ 149.99 => 14.95 ],
  [ inf    => 18.95 ],
);

my %extra_fees_per_state = (
  AK => 25.00,
  HI => 25.00,
);
然后:

my$shipping;
我的$shipping_费用(@shipping_费用){
我的($max,$fee)=@$shipping\u费用;

如果($subtotal,那么代码就是一团乱麻,有多个语法错误,并且违反了DRY

最好先计算基本运费,具体取决于小计。第二步,如果所在州是夏威夷或阿拉斯加,则添加25美元的费用:

my @shipping_fees = (
  # max subtotal => fee
  [  24.99 => 10.95 ],
  [  74.99 => 13.95 ],
  [ 149.99 => 14.95 ],
  [ inf    => 18.95 ],
);

my %extra_fees_per_state = (
  AK => 25.00,
  HI => 25.00,
);
然后:

my$shipping;
我的$shipping_费用(@shipping_费用){
我的($max,$fee)=@$shipping\u费用;

如果($subtotal感谢TLP我同意哈希将做出更明智的选择。立即测试。不要忘记使用
使用严格;使用警告;
。感谢TLP我同意哈希将做出更明智的选择。立即测试。不要忘了使用
使用严格;使用警告;
。阿蒙-感谢您验证代码是一团乱麻…继承自其他开发人员。将修订和测试。阿蒙-感谢您验证代码是一个完全混乱的…从另一个开发人员继承。将修订和测试。