Quoting string array in Join?

Quoting string array in Join?

am 01.10.2007 13:30:34 von 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
:)

Re: Quoting string array in Join?

am 01.10.2007 13:44:43 von 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

Re: Quoting string array in Join?

am 01.10.2007 14:31:59 von 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

Re: Quoting string array in Join?

am 01.10.2007 15:14:19 von 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

Re: Quoting string array in Join?

am 01.10.2007 18:55:02 von 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."