Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Smoothing text input

by johngg (Abbot)
on Aug 29, 2012 at 17:08 UTC ( #990511=note: print w/ replies, xml ) Need Help??

in reply to Smoothing text input

but the "map" is not doing what i expected

That's because the result of the map that is passed out is the result of the last statement in it. You are not passing $_ out of your map, just the result (number of substitutions) of the s/ $//;. Consider the following two code snippets.

$ perl -E ' > @arr = qw{ > abCdeFg > hIJklMn > OpqrsTu > }; > say join q{:}, @arr; > $str = join q{:}, > map { s{[A-Z]}{*}g } @arr; > say $str;' abCdeFg:hIJklMn:OpqrsTu 2:3:2 $
$ perl -E ' > @arr = qw{ > abCdeFg > hIJklMn > OpqrsTu > }; > say join q{:}, @arr; > $str = join q{:}, > map { s{[A-Z]}{*}g; $_ } @arr; > say $str;' abCdeFg:hIJklMn:OpqrsTu ab*de*g:h**kl*n:*pqrs*u $

Notice the different result when I pass $_ out of the map by mentioning it in a final statement.

I hope this is helpful.



Comment on Re: Smoothing text input
Select or Download Code
Replies are listed 'Best First'.
Re^2: Smoothing text input
by Anonymous Monk on Aug 29, 2012 at 17:43 UTC
    Doh! Of course. Thank you!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2015-11-30 08:54 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (766 votes), past polls