Joe W
Joe W

Reputation: 1872

Quote word function with an undef entry

When using quote word in perl is it possible to have a undef value in the list?

my @ number_array = qw( 1 2 3 4 5 6 7 8 9 10 )

What I am wondering is would it be possible to add a undef value to that list so that it contained 11 values instead of 10?

Upvotes: 2

Views: 323

Answers (2)

ikegami
ikegami

Reputation: 385897

qw(...)

is equivalent to

(split(' ', q(...), 0))

As for the answer to your question, it depends on what you mean by "null".

  • undef? No. split returns strings.
  • Empty string? No. split cannot return those with those operands.
  • Zero? Yes.
  • U+0000? Yes.

You would have to build your list by another means. For example,

my @array = (qw( 1 2 3 4 5 6 7 8 9 10 ), undef);

Or even the similar

my @array = (1..10, undef);

Upvotes: 5

Oleg V. Volkov
Oleg V. Volkov

Reputation: 22421

There's no null in perl, but you can use undef. Since qw explicitly operates only with space-separated string, you'd have to specify it outside of qw, but you can easily write several lists inside brackets:

my @number_array = (undef, qw( 1 2 3 4 5 6 7 8 9 10 ));
print scalar @number_array;

>11

Upvotes: 5

Related Questions