Hi, As a last resort, I am posting my question here (I only post if I have thoroughly searched the net, and my Perl books), so I really appreciate any help that any PHP experts (who know a bit of Perl) would give.
I have a huge text file, in all capital letters, with thousands of book
titles. For my example here, I will show just 5 lines of it. Here is exactly what it looks like:
COOKING BASICS (W/CD), 3RD EDITION
LESSONS IN COOKING, 5TH EDITION
HOW TO COOK (PAPERBACK), 3RD EDITION
HOW TO PREPARE FOOD (W/CD-ROM), 3RD EDITION
Precisely what I want to do: replace ALL occurences of
both "W/CD" and "W/CD-ROM" with the following:
"W/CD-ROM INCLUDED"
So, that after running my Perl Script on the above list, it will read
like this:
COOKING BASICS (W/CD-ROM INCLUDED), 3RD EDITION
LESSONS IN COOKING, 5TH EDITION
HOW TO COOK (PAPERBACK), 3RD EDITION
HOW TO PREPARE FOOD (W/CD-ROM INCLUDED), 3RD EDITION
So, as you see, only the "W/CD" and "W/CD-ROM" has been replaced. The,
"PAPERBACK", even though it's in parentheses, and all other stuff is properly left unchanged.
One of the scripts I tried to use, but wouldn't work is these two lines
of code:
$book[title] =~ s/(W/CD)\b/ W/CD-ROM INCLUDED/;
$book[title] =~ s/(W/CD-ROM)\b/ W/CD-ROM INCLUDED/;
Well.... those lines of code don't work at all. In fact, there is probably just one simple line of code that would accomplish what I want. One of the problems I run into is that the character, "W" has "special meaning" in Perl, and putting a backslash before it didn't help. Also, in the "W/CD" there is also a slash in there that has "special meaning" and I am getting totally confused with all of the forward slashes and backslashing I have to do and nothing is working. Also, I am hoping a line of code can be made in sort of the same format as $book[title] =~ blah blah blah, rather than using an if/then statement, in this format: if $book[title] contains W/CD { $book[title] = somethingelse } because I heard that "if/then" routines put a strain on servers. Could someone please help? Thank you!!