Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: substitute within elements of array

by kcott (Chancellor)
on Apr 09, 2013 at 10:18 UTC ( #1027700=note: print w/replies, xml ) Need Help??


in reply to substitute within elements of array

G'day Dr Manhattan,

You say "... ending with ,|?|! ..." but your regex (s/(\.|\?|\!)$//) isn't removing commas. Is that the bit that isn't working? You really need to show your input and output: "it does not work" is an entirely inadequate error report.

I think you'd be better off with a single character class ([?!,]) than an alternation with all those escaped characters:

$ perl -Mstrict -Mwarnings -E ' my @words = ("what?", "what!", "what,"); say for map { s/[?!,]$//; $_ } @words; ' what what what

-- Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027700]
help
Chatterbox?
[LanX]: it's pretty ironic if you know the character
choroba likes the movie
[choroba]: Lady_Aleena Do you really need to say "WorldBuilder" after having said "WorldBuilding"?
[LanX]: have to watch it again :)
[Lady_Aleena]: choroba, the tables in that group of modules is from the World Builder's Guidebook, so I thought it best to add the name of the book to the name of the module.
[choroba]: oh, I see
[Lady_Aleena]: There is the RolePlaying:: WorldBuilding:: WorldBuildersGuide book suite and the RolePlaying:: WorldBuilding:: HighLevelCampaigns suite.

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2017-05-24 22:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?