Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: map array elements with single quotes

by karthigayan (Initiate)
on Mar 10, 2010 at 09:07 UTC ( #827726=note: print w/ replies, xml ) Need Help??


in reply to Re: map array elements with single quotes
in thread map array elements with single quotes

First of all the way you used map is wrong . There is some unbalanced brace also . It should be like the following,

use strict; use warnings; my @foo = ('usa', 'cananda', 'strawberry'); @foo = map { "'$_'"} @foo; print @foo;


Comment on Re^2: map array elements with single quotes
Download Code
Re^3: map array elements with single quotes
by almut (Canon) on Mar 10, 2010 at 09:52 UTC

    First of all, it would've been more appropriate for you to respond to the original post, not to ikegami's reply — he didn't use map the wrong way :)

    Next, while your observation is correct, you seem to have overlooked the fact that the original poster is getting an unwanted trailing comma.

    Your solution could be fixed by changing the output field separator $,

    ... $, = ","; print @foo;

    or (to keep the effect localized)

    ... { local $, = ","; print @foo; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2014-09-17 13:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (81 votes), past polls