Removing apostrophe from string - causing error

Bill_B
Bill_B used Ask the Experts™
on
I dont think this is too difficult, but I cannot figure out what I am doing wrong here and my eyes are going crazy from looking at it. I am working on a shopping cart submission script and it is working fine, EXCEPT for when I add an item that has an apostrophe in the title. At that point, it all breaks down. I need to comment out that apostrophe for one subroutine only and it really doesn't even matter if the apostrophe is represented because I don't display or use the title field in this subroutine. Basically, I just need to remove whatever illegal characters that are causing my string (cleanItemsOrdered) to end abruptly at the apostrophe so that I can get the information from other parts of this variable.

Any advice would be greatly appreciated.

Here's the code:

######################################
#  RECEIVE VARIABLES FROM FORM SUBMIT        
######################################

my $itemsOrdered = param("itemsOrdered");
my $hiddenSubTotal = param("hiddenSubTotal");


######################################
#  CLEAN STRING AND SEND TO SUBROUTINE        
######################################

my $dsearchstring="'";
my $dreplacestring=" ";
my $cleanItemsOrdered = $itemsOrdered;
$cleanItemsOrdered =~ s/$dsearchstring/$dreplacestring/gi;

my $coupon_amount;
my $coupon_amount = &check_coupon_validity($cleanItemsOrdered,$hiddenSubTotal);

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
what exactly does not work in your example?
Could you give an example for $itemsOrdered

Probaly you have a backtick ` and not a apostrophe '

Author

Commented:
What happens is that my subroutine does not receive all of the information when I add a title with an apostrophe (not backtick) to my order. So, for example, if I do not have a title with an apostrophe, my $cleanItemsOrdered content looks like:

The Rolling Stones - Exile|images/RS.gif|3|AB123|CD|15.00~Motorhead - Ace of Spades|images/MH.gif|3|AB175|CD|15.00

but if I add a new item with an apostrophe in the title, the $cleanItemsOrdered string is cut off at that point. So, if I add The Go-Go's - Beauty and the Beat to this order, my $cleanItemsOrdered content looks like:

The Go-Go

Again, I don't really care about the title string in this part of this subroutine, so I could even get the cleaning function to remove apostrophes so that the full string is passed to my subroutine, that would be fine with me. The title is not used at all, so it can be mutilated as long as the other sections, like catalog number and quantity, are still passed along.

Thanks!

Author

Commented:
I've figured out the answer to this problem. The reason that my substitution was not achieving the desired result is because it was not receiving the correct info from the submission form. The apostrophe was cutting off in the submission form, so I needed to go back and do the string replace in my previous page. So, the problem is not here in my perl script, but in the HTML form.

This problem is solved and I would like to suggest that it be deleted, because it was a dumb mistake and is misleading because the code is correct.
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

ask support @ EE for deleteing the question

Author

Commented:
Ok, I have notified support. Thanks and sorry for the confusion.
Points refunded and placed in PAQ

Computer101
E-E Admin

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial