in reply to Why doesn't this work?

For me, your first example works:

C:\Dokumente und Einstellungen\corion>perl -MData::Dumper -e "{$_=[];l +ocal $/=qq(\n); @$_=<>};warn Dumper $_; my $count=@$_; print $count, +' lines';" \boot.ini $VAR1 = [ '[boot loader] ', ... ]; 5 lines

while the second one does always output "1 lines". This is the special behaviour of split. To make split produce more results than needed on the left hand side, you need to give it a LIMIT. Also, you will want to call split in list context using this operator =()=:

> perl -e "{$/=undef, $_=<>} my $count=()=split /\n/,$_,-1; print $cou +nt" \boot.ini 6

Replies are listed 'Best First'.
Re^2: Why doesn't this work?
by perl-diddler (Chaplain) on Apr 12, 2013 at 21:55 UTC
    Huh?... but the 2nd one worked. What did you do to your perl that it doesn't? I'm using this split:
    Splits the string EXPR into a list of strings and returns the list in list context, or the size of the list in scalar context. Size of list in scalar context. && re: limit: If LIMIT is omitted (or, equivalently, zero), then it i +s usually treated as if it were instead negative but with + the exception that trailing empty fields are stripped (empt +y leading fields are always preserved);
    What version of split are you using?

      Ah, sorry - I don't know what I did wrong while testing this. The documentation is correct and neither the limit nor the forced list context are needed:

      > perl -e "{$/=undef, $_=<>} my $count=split /\n/; print $count" \boot +.ini

      works just as well, and just as documented.