Gossamer Forum
Home : General : Perl Programming :

This is For Eliot Lee - Challenge

Quote Reply
This is For Eliot Lee - Challenge
Hi Eliot, or All. I have a big problem to solve, please see if you can help me.

Imagine i have this string:

"(a**2) - (b**2) + 4*a*b"

I want a code that goes through the string and substitute the values, like this:
a ====> alabama
b ====> boston

So, it would be like:
(alabama**2) - (boston**2) + 4*alabama*boston

Is there any way to do it???????? Thanks a lot.

Thanks Gordon And Eliot for the usefull help.

[This message has been edited by CarloFalci (edited January 16, 2000).]
Quote Reply
Re: This is For Eliot Lee - Challenge In reply to
Code:
%names = (
a => 'alabama',
b => 'boston'
);
s/(a|b)/$names{$1}/g;

-- Gordon

------------------
$blah='82:84:70:77';
print chr($_) foreach (split/:/,$blah);

Quote Reply
Re: This is For Eliot Lee - Challenge In reply to
There are many other more proficient Perl programmers, like Widgetz, Gordon, Chris, etc. than me. They would probably all agree that I am more a code hacker than a programmer. Please just post your general questions and do not address me individually.

Wink

Thanks.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------




Quote Reply
Re: This is For Eliot Lee - Challenge In reply to
gclemmons..

because it is all on one line.. it won't switch alabama to

albostonama

right? Smile

jerry
Quote Reply
Re: This is For Eliot Lee - Challenge In reply to
it doesn't matter how many lines it is on

-- Gordon


------------------
$blah='82:84:70:77';
print chr($_) foreach (split/:/,$blah);

Quote Reply
Re: This is For Eliot Lee - Challenge In reply to
Try s/^b/boston/i

owen
Quote Reply
Re: This is For Eliot Lee - Challenge In reply to
s/^b/boston/i
will only convert 'b's that are the first character in the string and will only do one per string.

-- Gordon


------------------
$blah='82:84:70:77';
print chr($_) foreach (split/:/,$blah);