If I understand what you're saying correctly, that's a documented behavior:

>From https://perldoc.perl.org/functions/split.html

> If LIMIT is omitted (or, equivalently, zero), then it is usually treated
as if it were instead negative but with the exception that trailing empty
fields are stripped (empty leading fields are always preserved); if all
fields are empty, then all fields are considered to be trailing (and are
thus stripped in this case).

You're not nuts, it's doing what it's documented to do.

(I've been lurking this mailing list for a long time, and for the first
time I actually know the answer off the top of my head.)

Quinn

On Fri, May 29, 2020, 2:15 PM Greg London <em...@greglondon.com> wrote:

>
> I feel like I'm losing my mind on this.
> Why would perl do this?
>
>
> This script:
>
>
> #!/bin/env perl
>
> use warnings;
> use strict;
> use Data::Dumper;
>
>
> my $block=<<'BLOCK';
>
> alpha
> bravo
>
>
> charlie
> delta
>
>
>
> BLOCK
> ;
>
> print "block is:vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n";
> print $block;
> print "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n";
>
> my @lines = split(/\n/, $block);
>
> print "when I split on \\n, I get this:\n";
> print Dumper \@lines;
>
>
>
>
>
> OUTPUT OF SCRIPT IS:
>
> block is:vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
>
> alpha
> bravo
>
>
> charlie
> delta
>
>
>
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> when I split on \n, I get this:
> $VAR1 = [
>           '',
>           'alpha',
>           'bravo',
>           '',
>           '',
>           'charlie',
>           'delta'      <======== SHOULD BE SOME BLANK ENTRIES AFTER DELTA
>         ];
>
> _______________________________________________
> Boston-pm mailing list
> Boston-pm@pm.org
> https://mail.pm.org/mailman/listinfo/boston-pm
>

_______________________________________________
Boston-pm mailing list
Boston-pm@pm.org
https://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to