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.



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 monks are getting baked in the sun...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2017-06-25 15:09 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (567 votes). Check out past polls.