SPUG:Help with substitution
John Subaykan
cansubaykan at hotmail.com
Thu May 15 21:28:59 CDT 2003
use \Q to disable pattern metacharacters (until \E)
($new_data = $data) =~ s/\Q$pattern\E/something new/;
John
----Original Message Follows----
From: "Nord, Chris" <chris.nord at attws.com>
To: <spug-list at pm.org>
Subject: SPUG:Help with substitution
Date: Thu, 15 May 2003 16:33:34 -0700
I am having trouble with substitution when the variable $pattern
contains non-word characters. See example 1. Ideas on how to make
example 1 work like example 2? I have tried a few variations when
creating $pattern, but so far have not got the substitution to work.
Thanx,
Chris Nord
AT&T Wireless Services
WNS Call Routing Translations
office 425 288 2031
fax 425 806 3690
###################################################
#! /bin/perl -w
$data = '(PREXLIDX 501) ( CARRMNC (TEST)$)$ $';
$pattern = '( CARRMNC (TEST)$)';
## example 1
($new_data = $data) =~ s/$pattern/something new/;
print $new_data,"\n";
# output: (PREXLIDX 501) ( CARRMNC (TEST)$)$ $
## example 2
($new_data = $data) =~ s/\( CARRMNC \(TEST\)\$\)/something new /;
print $new_data,"\n";
# output: (PREXLIDX 501) something new $ $
###################################################
_____________________________________________________________
Seattle Perl Users Group Mailing List
POST TO: spug-list at mail.pm.org
ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list
MEETINGS: 3rd Tuesdays, U-District, Seattle WA
WEB PAGE: www.seattleperl.org
_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
More information about the spug-list
mailing list