escape whitespace in qw/ /

C

chris

I have a whitespace separated list where some of the fields actually
should have a extra whitespace character. Is there a way I can escape
this space so I can use qw// to create the list:

@list = qw/ 1.0 UK Y 2.5 /;

where UK is actually 'UK ' (without the quotes).

Is this possible?

Thanks in advance...
 
T

Tore Aursand

I have a whitespace separated list where some of the fields actually
should have a extra whitespace character. Is there a way I can escape
this space so I can use qw// to create the list:

@list = qw/ 1.0 UK Y 2.5 /;

where UK is actually 'UK ' (without the quotes).

Is this possible?

I don't think so (after reading 'perldoc perlop'), but you can always use
your imagination;

my @list = split(',', '1.0,UK ,Y,2.5');

:)
 
M

Matija Papec

X-Ftn-To: chris

I have a whitespace separated list where some of the fields actually
should have a extra whitespace character. Is there a way I can escape
this space so I can use qw// to create the list:

@list = qw/ 1.0 UK Y 2.5 /;

where UK is actually 'UK ' (without the quotes).

Is this possible?

I think it isn't, as it seems that perl immediately convert qw// to list
E:\>perl -MO=Deparse -e "@list = qw/ 1.0 UK Y 2.5 /;"
@list = ('1.0', 'UK', 'Y', '2.5');

but you could use some other character instead space,
@list = map { tr/_/ /; $_ } qw/ 1.0 UK_ Y 2.5 /;
 
T

Tad McClellan

chris said:
I have a whitespace separated list where some of the fields actually
should have a extra whitespace character. Is there a way I can escape
this space


No.

qw is not the Right Tool if the data contains whitespace.

so I can use qw// to create the list:


You can still use qw// to create the parts of the list
that do not contain whitespace.

@list = qw/ 1.0 UK Y 2.5 /;

where UK is actually 'UK ' (without the quotes).

Is this possible?


@list = qw/ 1.0 /, 'UK ', qw/ Y 2.5 /;

or even:

@list = qw/ 1.0 UK Y 2.5 /;
$list[1] .= ' ';
 
L

Leon

chris said:
I have a whitespace separated list where some of the fields actually
should have a extra whitespace character. Is there a way I can escape
this space so I can use qw// to create the list:

@list = qw/ 1.0 UK Y 2.5 /;

where UK is actually 'UK ' (without the quotes).

@list = ('1.0', 'UK ', 'Y', '2.5');
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top