Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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 meditating upon the Monastery: (9)
As of 2015-07-04 08:31 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 (58 votes), past polls