in reply to Leading empty array elements after splitting

If you use warnings, you’ll see that the /g modifier on the regex has no effect within a split. But why not keep the modifier, change \D to \d+, and dispense with split altogether?

1:22 >perl -MData::Dump -wE "my $input = 'MD:Z:4C3C7C0T2^T9C44'; my @ +test = $input =~ /\d+/g; dd \@test;" [4, 3, 7, 0, 2, 9, 44] 1:22 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Leading empty array elements after splitting
by Anonymous Monk on Aug 22, 2016 at 16:20 UTC
    use warnings; use strict; Are always on for me - no warning was given, odd!

      What version of Perl are you using (perl -v)?

      On both 5.20.3 and 5.24.0, this code produces the following warning:

      perl -wMstrict -E 'my @test = split((/\D/g), "x4d77");' Use of /g modifier is meaningless in split at -e line 1.
        5.25.2