Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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.

Cheers,

JohnGG


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2014-12-18 18:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (59 votes), past polls