Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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 all is quiet...

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

    Results (297 votes). Check out past polls.