in reply to Fun with learning maps

I just had to add a bit more to this. The alternate form of the code that would have helped jeffa the most was: print join("\n", map { split; $_ =~ s/-//g;} @words); With the split and substitution reversed, you would have discovered quite quick that s/// and tr/// always return counts, even in the list context that map provides. I bet you have seen foreach (/PATTERN/) {} and figured that s/// and tr/// work like m// does in that idiom. Read a bit of `perldoc perlop` and you will find that in the section "Regexp Quote-Like Operators" it explains m// behavior in a list (returns the list of matches) but makes no such claims about the other two. This has bit me before. =) BTW, with your first example and with the others that were provided, you should also do a: print join("\n", @words); And note the side effects of your code on your original data.

Replies are listed 'Best First'.
(jeffa) RE: RE: Fun with learning maps
by jeffa (Bishop) on Jun 28, 2000 at 01:54 UTC
    Now that is very interesting:
    My first try produces the desired output, but it mangles the original data: in particular the dashes are removed, but there are still 4 elements as opposed to 7.

    The second try does not produce the desired output (it returns the truth of the substituion match), but the original data is intact.

    Very interesting . . . I will study this more, but now it's time for rush hour traffic!!

    Thanks all!