Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: What is wrong here (Replacing Strin pieces)

by rjt (Deacon)
on Jul 16, 2013 at 11:22 UTC ( #1044558=note: print w/ replies, xml ) Need Help??


in reply to What is wrong here (Replacing Strin pieces)

The -+ matches all dashes at the start/end of the string, but you're replacing them with a single ?. You need to stuff in as many question marks as there were dashes. One way out of many, using eval (/e):

use 5.012; my $string = "---------xxxxxxxxxxxxxxx------yyyyyyyyyyyyyy--------"; say $string; $string =~ s/(\A\-+|\-+$)/'?' x length $1/eg; say $string;

Output:

---------xxxxxxxxxxxxxxx------yyyyyyyyyyyyyy-------- ?????????xxxxxxxxxxxxxxx------yyyyyyyyyyyyyy????????


Comment on Re: What is wrong here (Replacing Strin pieces)
Select or Download Code
Re^2: What is wrong here (Replacing Strin pieces)
by Anonymous Monk on Jul 16, 2013 at 11:40 UTC
    Thank you! I replaced with with only one ?, didn't think of that! I will also study the perlintro again. A long way to wisdom ;)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2015-07-06 18:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (80 votes), past polls