Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: String Substitution Operator

by TheHobbit (Pilgrim)
on Oct 23, 2003 at 09:10 UTC ( [id://301506]=note: print w/replies, xml ) Need Help??


in reply to String Substitution Operator

Hi,
I'd realy like to know what this reference is... People that write that sort of things should be hung and sent to the programmers' hell, where they'll have to write useless software in VB for the eternity... (I'm doing right this now, writing useless software in VB I mean, and I can not immagine a better definition of programmers' hell).

Obviously,

$string =~ s/\d{2} (\W) \d{2} \1 \d{2}/$1-$2-$3/x

does not what that wanna be reference says. Infact, it also is semanticaly wrong, $2 and $3 being undefined in the replacement part: the matching part of the s/// operator contains only one pair of parenthesis, so that only $1 is defined.

The sobstitution you propose almost does the work. I say almost because:

  1. it replaces only the first not-word character it founds in $string: use the /g option to solve this problem
  2. it replaces any not-word character, not just slashes.

a third problem (that could be disregarded) is that the /x option is useless, since there are nor spaces nor comments in the regex.

A simpler way to to that would be to use the tr/// operator, like in

$string =~ tr!/!-!;

Obvously, all this still lets you short of an useful example about how and why use the /x option in matching operators. I'm sorry, but I have none to offer to you now, may be later, when I'll be at home with all my little files at hand...

Hoping that this helps...


Leo TheHobbit

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://301506]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-19 04:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found