Why is there an additional empty element in the array after splitting a string using regex in Perl?

Viewed 37

In the code below, what is the reason behind $tmp[0] being empty?

my $ver = "Q050";
my @tmp = ();

if ($ver =~ /Q0\d\d/) {
    @tmp = split(/Q0/, $ver);
}
print("tmp: @tmp\n");
print("tmp[0] = $tmp[0]\n");
print("tmp[1] = $tmp[1]\n");

Output -

tmp:  50
tmp[0] =
tmp[1] = 50

Am i missing something here? Thanks.

0 Answers
Related