Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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]
[choroba]: exceptions to this rule are rare

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2018-03-20 10:44 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (250 votes). Check out past polls.