Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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;

Replies are listed 'Best First'.
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?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2016-10-24 22:09 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (310 votes). Check out past polls.