jbullock35 has asked for the wisdom of the Perl Monks concerning the following question:
I have an array of strings. I want to wrap each string in quotation marks—that is, to prepend and append a quotation mark to each string—unless the string matches a certain pattern. There are many ways to do this, but I want to know why I'm having trouble doing it with map. Here is some example code: |
my @strings = qw(boy bird FALSE); @strings = map { unless (/FALSE/) { "\"$_\"" }} @strings;
I want this to return "boy" "bird" FALSE but it returns "boy" "bird" 1 and I can't quite figure out why. The 1 appears to come from scalar evaluation of unless (/FALSE/), but why? It seems that $_ is being set to 1 at some point, but I don't see why that should be, either. |
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: using map with compound code blocks to alter strings: a strange result
by kyle (Abbot) on Jun 15, 2007 at 15:53 UTC | |
Re: using map with compound code blocks to alter strings: a strange result
by eric256 (Parson) on Jun 15, 2007 at 19:03 UTC | |
Re: using map with compound code blocks to alter strings: a strange result
by hangon (Deacon) on Jun 16, 2007 at 06:37 UTC | |
Re: using map with compound code blocks to alter strings: a strange result
by andreas1234567 (Vicar) on Jun 15, 2007 at 17:56 UTC | |
by kyle (Abbot) on Jun 15, 2007 at 18:07 UTC |
Back to
Seekers of Perl Wisdom