Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: What is wrong here (Replacing Strin pieces)

by choroba (Abbot)
on Jul 16, 2013 at 11:23 UTC ( #1044560=note: print w/ replies, xml ) Need Help??


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

It is possible, but I am not sure it is comprehensible. I would not recommend it for production code:

$string =~ s/\A(-+)|(-+)$/("?" x length $1).("?" x length $2)/eg;
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: What is wrong here (Replacing Strin pieces)
Download Code
Re^2: What is wrong here (Replacing Strin pieces)
by AnomalousMonk (Abbot) on Jul 16, 2013 at 16:23 UTC
    $string =~ s/\A(-+)|(-+)$/("?" x length $1).("?" x length $2)/eg;

    That does the substitutions, but will also produce warnings if run with warnings:

    >perl -wMstrict -le "my $s = '---------xxxxxxxxxxxxxxx------yyyyyyyyyyyyyy--------'; print qq{'$s'}; ;; $s =~ s{ \A (-+) | (-+) \z } { ('?' x length $1) . ('?' x length $2) }xmsge; print qq{'$s'}; " '---------xxxxxxxxxxxxxxx------yyyyyyyyyyyyyy--------' Use of uninitialized value $2 in repeat (x) at -e line 1. Use of uninitialized value $1 in repeat (x) at -e line 1. '?????????xxxxxxxxxxxxxxx------yyyyyyyyyyyyyy????????'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (15)
As of 2014-09-18 14:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (116 votes), past polls