Ask a Question related to PERL Beginners, Design and Development.
-
Michael Goodman #1
substitute character in variable
Pardon my ignorance but,
How do you parse a variable to find every occurrence of a string and
replace the string with another. I tried using ~s/ but it doesn't work.
Thanks,
Michael Goodman Guest
-
Escape character when setting variable
I'm unsure on how to escape a character when setting a session variable. Here's my problem, I'm getting an outside variable that contains a dash in... -
Substitute for mod function
Hi all! I need to find a substitute for the mod function which can be found in vbscript and so on. Example: for i = 0 to 100 if (i mod... -
Using More Than 1 Substitute ?
I have a mess of text in 1 field. 140$042$024$104 etc ... I want to have 1 calc field that fixes all of it with a key. Substitute (text,... -
character limitation of an application variable
Does anyone know the character limitation of an application variable ?? How much can one hold ? Will it give an error if it gets too big ? etc... -
Need substitute for SSI GLOBAL
Hello, I'm trying to port a website from GoServer to IIS 5.1 and it makes a lot of use of SSI. Under GoServer I could set GLOBAL variables,... -
Marcos Rebelo #2
RE: substitute character in variable
give one example
-----Original Message-----
From: Michael Goodman [mailto:mgoodman@BTBOCES.ORG]
Sent: Friday, September 12, 2003 3:27 PM
To: [email]beginners@perl.org[/email]
Subject: substitute character in variable
Pardon my ignorance but,
How do you parse a variable to find every occurrence of a string and
replace the string with another. I tried using ~s/ but it doesn't work.
Thanks,
--
To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
For additional commands, e-mail: [email]beginners-help@perl.org[/email]
Marcos Rebelo Guest
-
Rob Dixon #3
Re: substitute character in variable
Hi Michael
Michael Goodman wrote:This is a beginners list :)>
> Pardon my ignorance but,
use strict;> How do you parse a variable to find every occurrence of a string and
> replace the string with another. I tried using ~s/ but it doesn't work.
use warnings;
my $variable = "A and B and C and D and E";
$variable =~ s/and/or/g;
print "$variable\n";
OUTPUT
A or B or C or D or E
HTH,
Rob
Rob Dixon Guest
-
James Edward Gray II #4
Re: substitute character in variable
On Friday, September 12, 2003, at 08:27 AM, Michael Goodman wrote:
For replacing a string, you want:> Pardon my ignorance but,
>
> How do you parse a variable to find every occurrence of a string and
> replace the string with another. I tried using ~s/ but it doesn't
> work.
$variable =~ s/STRING/REPLACEMENT/g;
Just remember that's a Regular Expression, so some characters have
special meaning in there. Good luck.
James
James Edward Gray II Guest
-
Robin Norwood #5
Re: substitute character in variable
"Michael Goodman" <mgoodman@BTBOCES.ORG> writes:
Michael,> Pardon my ignorance but,
>
> How do you parse a variable to find every occurrence of a string and
> replace the string with another. I tried using ~s/ but it doesn't work.
It's usually better to post a code example so that we can see what's
going wrong. However, this quick example does what I think you are
asking for:
#!/usr/bin/perl
use strict;
use warnings;
my $string = "How much wood would a woodchuck chuck if a woodchuck could chuck wood?\n";
$string =~ s/wo/qu/g;
print $string;
returns:
How much quod quuld a quodchuck chuck if a quodchuck could chuck
quod?
Note the 'g' tacked on to the end of the substitution...
-RN
--
Robin Norwood
Red Hat, Inc.
"The Sage does nothing, yet nothing remains undone."
-Lao Tzu, Te Tao Ching
Robin Norwood Guest



Reply With Quote

