Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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;

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://827726]
help
Chatterbox?
[holli]: it's not always possible to do a complete rewrite without cutting off some pigtails
[Discipulus]: indeed! new firefox seems poorer: many tab crash, and you open this link in FF?
[Discipulus]: problem scrolling even main page..;=(
[LanX]: holli -> Good Intentions: Wikisyntax for the Monastery
[LanX]: monklinks are automatically converted ...
[LanX]: On another node, I just saw yesterday that the everything engine supports auto-paragraph whithout the need to type <p>

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2017-11-20 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (291 votes). Check out past polls.

    Notices?