Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: regex/substitution question

by slugger415 (Monk)
on Feb 07, 2012 at 19:32 UTC ( [id://952329]=note: print w/replies, xml ) Need Help??


in reply to Re: regex/substitution question
in thread regex/substitution question

Excellent! Thank you. I've not used "map" before so will have to study that one.

Regarding the use of \b, I'm wondering if my hash name contains a period at the end, what would happen? This seems to work fine but am I causing a potential problem? I guess my question is, since . is also a word boundary, might it leave it in in the substitution?

%subs = ("Xaa1." => "sub1"); foreach $s (keys %subs){ $data =~ s/\b$e\b[.]?/$subs{$s}/g; }

Anyway thanks much, this is very helpful.

UPDATE:

Ignore that last question. What I meant was, if $data contains a period after Xaa1, not the name in %subs. Here is my Xaa1. data string.

But I think I'm asking a confusing question.. so please ignore. :-)

Replies are listed 'Best First'.
Re^3: regex/substitution question
by ikegami (Patriarch) on Feb 07, 2012 at 21:43 UTC

    I'm wondering if my hash name contains a period at the end, what would happen?

    Depends on what you expect to follow the period, but I'm betting it wouldn't be appropriate to use \b.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-25 17:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found