Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

/proc/kallsyms format, sqldatasource dal, wwwxxxenden, convert raid5 to raid 10 mdadm, apache force chunked, nrao wwwxxx, xxxxxdup, procmail change subject header, wwwXxx not20, Wwwxxx.doks sas

Links

XODOX
Impressum

#1: Quoting string array in Join?

Posted on 2007-10-01 13:30:34 by pkaluski

Hello All,

Sorry I'm new to Perl, so the question might be very trivial... but i'm really stuck...

let say if i have: @items = ( "apple", "orange", "peal" );

and I want to join them into a string, so the string would look like this: "apple", "orange", "peal"

I know join can do $my_string = join(",", @items); , but how about my double quotes? how can I put
them in too? THanks

Thanks very much for all the helps, thanks
:)

Report this message

#2: Re: Quoting string array in Join?

Posted on 2007-10-01 13:44:43 by Gunnar Hjalmarsson

¦a²y¤H wrote:
> let say if i have: @items = ( "apple", "orange", "peal" );
>
> and I want to join them into a string, so the string would look like this: "apple", "orange", "peal"
>
> I know join can do $my_string = join(",", @items); , but how about my double quotes? how can I put
> them in too?

my $my_string = '"' . join('", "', @items) . '"';

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Report this message

#3: Re: Quoting string array in Join?

Posted on 2007-10-01 14:31:59 by pkaluski

:o so simple, why didn't I think of that...

Thanks Gunnar :)

Gunnar Hjalmarsson wrote:
> =A6a=B2y=A4H wrote:
>> let say if i have: @items =3D ( "apple", "orange", "peal" );
>>
>> and I want to join them into a string, so the string would look like t=
his: "apple", "orange", "peal"
>>
>> I know join can do $my_string =3D join(",", @items); , but how about =
my double quotes? how can I put
>> them in too?
>=20
> my $my_string =3D '"' . join('", "', @items) . '"';
>=20

Report this message

#4: Re: Quoting string array in Join?

Posted on 2007-10-01 15:14:19 by Dummy

¦a²y¤H wrote:
> Hello All,
>
> Sorry I'm new to Perl, so the question might be very trivial... but i'm really stuck...
>
> let say if i have: @items = ( "apple", "orange", "peal" );
>
> and I want to join them into a string, so the string would look like this: "apple", "orange", "peal"
>
> I know join can do $my_string = join(",", @items); , but how about my double quotes? how can I put
> them in too? THanks

my $my_string = join ',', map qq["$_"], @items;



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Report this message

#5: Re: Quoting string array in Join?

Posted on 2007-10-01 18:55:02 by rvtol+news

??? schreef:

> let say if i have: @items = ( "apple", "orange", "peal" );
>
> and I want to join them into a string, so the string would look like
> this: "apple", "orange", "peal"
>
> I know join can do $my_string = join(",", @items); , but how about
> my double quotes? how can I put them in too?

$perl -wle '
@a = qw(apple orange peal);
$s = do { local $"=q{", "}; qq{"@a"} };
print $s
'
"apple", "orange", "peal"

--
Affijn, Ruud

"Gewoon is een tijger."

Report this message