[ic] This is *very* weird...
Interchange user
interchange-users@icdevgroup.org
Fri Oct 18 17:51:00 2002
(Was Re: [ic] Prevent from ordering more than is in stock)
OK, I was trying to figure out why the following code wasn't working, pasted
into KEdit from KMail:
[perl tables=inventory]
my $item;
foreach $item (@{$Carts->{main}}) {
my $on_hand = tag_data('inventory', 'quantity', $item->{code});
next if $on_hand >= $item->{quantity};
if ($on_hand<=0) {
$item->{quantity} = 0;
$item->{q_message} = "Item is currently out of stock.";
} else {
$item->{quantity} = $on_hand;
$item->{q_message} = "Limited item stock, order quantity adjusted.";
}
}
[/perl]
In the end, I decided to rewrite it from scratch as follows:
[perl tables="inventory" failure="Error"]
my $item;
for $item(@$Items) {
my $on_hand = tag_data('inventory', 'quantity', $item->{code});
next if $on_hand >= $item->{quantity};
if ($on_hand <= 0) {
$item->{quantity} = 0;
$item->{q_message} = "Item is currently out of stock.";
} else {
$item->{quantity} = $on_hand;
$item->{q_message} = "Limited item stock, order quantity adjusted.";
}
}
[/perl]
It worked, but I was interested to know what was wrong with the original
code, so I copied bits from my version to try and narrow down the problem,
until I eventually ended up with an *identical* copy (yes, I'm sure) and it
still wouldn't work! I also re-typed the whole original listing, and it
worked!
So I had these four segments of code in the same page; the original pasted
code, my rewritten code, the edited original, and the re-typed original -
only the rewritten and re-typed versions worked.
WTF? If the ASCII characters are identical, why is pasting the code having
this effect?! I copied it into a hex editor and didn't notice any extra
special characters. Weird.