Hello,

Can anyone explain the difference between these two lines of code? The code
comes from a shopping cart I'm using.

The first line is from a script running on my current web server.  The
second is the same line modified to run on a new server that I am moving my
site to.  (The new server is a UNIX box.)


########################################################
## Begin Original code

<-- Some code -->

@chunks=split(/ID=/, $formdata);

foreach (split(/&/, shift(@chunks)))

 {
 ($name, $value)=split(/=/, $_);
 $name=~s/\+/ /g;
 $name=~s/%([0-9|A-F|a-f]{2})/pack(C,hex($1))/eg;
 $value=~s/\+/ /g;
 $value=~s/%([0-9|A-F|a-f]{2})/pack(C,hex($1))/eg;
 ${$name}=$value;
 }
foreach $chunk (@chunks)
 {
 $chunk=~/Quantity=([^&]+)/;  ### <-- ORIGINAL CODE
 next if ($1 eq "");
 ($item_id, $chunk)=split(/&/, $chunk, 2);
 foreach (split(/&/, $chunk))
  {
  ($name, $value)=split(/=/, $_);
  $name=~s/\+/ /g;
  $name=~s/%([0-9|A-F|a-f]{2})/pack(C,hex($1))/eg;
  $value=~s/\+/ /g;
  $value=~s/%([0-9|A-F|a-f]{2})/pack(C,hex($1))/eg;
  
  if ($value !~ /_/)
   {
   $$pointer{$name}=$value;
   }
  else
   {
   
   ($value, $price)=split(/_/, $value);
   $$pointer{$name}=$value;
   $$pointer{'Price'}+=$price;
   }
  }
 $data{$item_id}=$pointer;
 undef ($pointer);
 }

<-- Some code -->

## End Original code

########################################################

## Begin Modified code

<-- Some code -->

@chunks=split(/ID=/, $formdata);

foreach (split(/&/, shift(@chunks)))

 {
 ($name, $value)=split(/=/, $_);
 $name=~s/\+/ /g;
 $name=~s/%([0-9|A-F|a-f]{2})/pack(C,hex($1))/eg;
 $value=~s/\+/ /g;
 $value=~s/%([0-9|A-F|a-f]{2})/pack(C,hex($1))/eg;
 ${$name}=$value;
 }
foreach $chunk (@chunks)
 {
 $chunk=~/Quantity=([^&]*)/;  ### <-- Changed + tp *
 next if ($1 eq "");
 ($item_id, $chunk)=split(/&/, $chunk, 2);
 foreach (split(/&/, $chunk))
  {
  ($name, $value)=split(/=/, $_);
  $name=~s/\+/ /g;
  $name=~s/%([0-9|A-F|a-f]{2})/pack(C,hex($1))/eg;
  $value=~s/\+/ /g;
  $value=~s/%([0-9|A-F|a-f]{2})/pack(C,hex($1))/eg;
  
  if ($value !~ /_/)
   {
   $$pointer{$name}=$value;
   }
  else
   {
   
   ($value, $price)=split(/_/, $value);
   $$pointer{$name}=$value;
   $$pointer{'Price'}+=$price;
   }
  }
 $data{$item_id}=$pointer;
 undef ($pointer);
 }

<-- Some code -->

## End Modified code

########################################################

The original code works fine on the old server.  The second bit of code has
a modification to make the cart run on the new server.  The original code
for the cart was bought from a third party, but subsequently modified by my
self.  As a result, I'm am not clear on exactly how the bit of code that is
in question is working.  (I must admit I guessed at the change to get it to
work on the new server and eventually I got it to work - after many, many
hours of hacking.)

If I use the original line on the new server, the cart miscalculates and
writes corrupted data into the transaction file - but only if the second to
last cart item on any page is selected.  If any other selection is made or
added, the cart works fine.

For my own reference, I'm curious as to why this modification makes a
difference and why it is required to run properly.

Thanks in advance!

Greg

Reply via email to