I've read as many previous posts as I could stand and have not found a problem quite like this one. It seems easy enough to do, but I give up. A little help?
Here's the situation and problem...
I get data from my credit card service provider after a sale via "GET" and create an array of all the data passed (Thanks tsdragon...I lifted some of your code from a previous post!) like this:
The problem...I always get array elements named "quantitiy", "id" and "desc". I can print them like this, no problem:
Now for the REAL problem...
When there are additional items ordered, the array elements are named "quantity1", "id1" and "desc1", etc. I CANNOT figure how to print out these additional elements after I print the one that I know and can hard-code. Here is what I've tried so far:
I've tried every combination of $x, [$x], {$x}, ($x) and even \$x I can think of and none of it prints out the additional items.
(side note -- I am aware that the above code will print a bunch of blank lines for elements that don't have a number in their name -- I'll fix that later).
Any help would be GREATLY appreciated.
Thanks,
Tom
Here's the situation and problem...
I get data from my credit card service provider after a sale via "GET" and create an array of all the data passed (Thanks tsdragon...I lifted some of your code from a previous post!) like this:
Code:
# Split data into list (array) of key=value entries
@order_info = split(/&/, $buffer);
# Process the data passed in buffer through POST
foreach $x (0 .. $#order_info) {
# Convert plus signs back to spaces
$order_info[$x] =~ s/\+/ /g;
# Split into key and value (on the first equal sign found).
($key, $val) = split(/=/, $order_info[$x], 2);
# Convert %XX sequences into characters
$key =~ s/%(..)/pack("c", hex($1))/ge;
$val =~ s/%(..)/pack("c", hex($1))/ge;
# Replace list element with converted values
$order_info[$x] = $key . "=" . $val;
# Create associative array member
$order_info{$key} = $val;
}
The problem...I always get array elements named "quantitiy", "id" and "desc". I can print them like this, no problem:
Code:
print "Product ID: $order_info{'id'}<br>\n";
print "Quantity : $order_info{'quantity'}<br>\n";
print "Prod Description: $order_info{'desc'}<br>\n";
Now for the REAL problem...
When there are additional items ordered, the array elements are named "quantity1", "id1" and "desc1", etc. I CANNOT figure how to print out these additional elements after I print the one that I know and can hard-code. Here is what I've tried so far:
Code:
# Print any additional items ordered
foreach $x (1 .. $#order_info) {
print qq(Quantity: $order_info{'quantity$x'}<br> ID: order_info'id$x'}<br>
DESC: $order_info{'desc$x'}<br>\n);
}
I've tried every combination of $x, [$x], {$x}, ($x) and even \$x I can think of and none of it prints out the additional items.
(side note -- I am aware that the above code will print a bunch of blank lines for elements that don't have a number in their name -- I'll fix that later).
Any help would be GREATLY appreciated.
Thanks,
Tom