Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function similar to Replace in ASP

Status
Not open for further replies.

Quinveros

MIS
Apr 30, 2001
2
0
0
BE
Hi,

I need to know if perl have a function similar to Replace in ASP. I want to replace a dot(.) and a comma in a value for nothing.

Thank you.
 
Perl has a substitute function - read the perldoc by doing "perldoc perlop" and search for "substitution" - you'll find a section that starts with

s/PATTERN/REPLACEMENT/egimosx

To substitute for both dot and comma, you'd need 2 substitute commands - one for each.

There's also a "transliteration" function like

tr/SEARCHLIST/REPLACEMENTLIST/cds

and can also be found in "perldoc perlop". Here's a little test I did with tr:

### tr (transliterate) example ###
my $c = "abc,def.ghi";
print &quot;\$c before = <$c>\n&quot;;

print &quot;\$c after = <$c>\n&quot;;

Output:
------
$c before = <abc,def.ghi>
$c after = <abc def ghi>

if you just want to *remove* the dot and the comma, then your tr would look like this:

$c =~ tr/,.//d; # d for delete

HTH.

Hardy Merrill
Mission Critical Linux, Inc.
 
lucid,
why the []s?

Won't this work?
$var =~ s/\.|,//g;

??


keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top