Perl split function

my @d =split('\|', $_);
west|ACH|3|Y|LuV|N||N||
Qt|UWST|57|Y|LSV|Y|Bng|N|KT|

It Returns d as 8 for First Line, and 9 as for Second Line . I want to Process Both the Files, How to Handle It.

Hi,

It seems ok for me, take a look:

$ cat script.pl
use warnings;
use strict;

while ( <DATA> ) {
        my @d =split('\|', $_);
        printf "%s -> %d\n", qq[Number of fields of line $.], scalar @d;
}

__DATA__
west|ACH|3|Y|LuV|N||N||
Qt|UWST|57|Y|LSV|Y|Bng|N|KT|
$ perl script.pl
Number of fields of line 1 -> 10
Number of fields of line 2 -> 10
while(defined ( $_ = <DAT>))
      {
              chomp;
              my @d =split('\|', $_);
              $size = @d;
              print "$size";
}

This is wat i am using but it Gives me 8 and 9
The Max should Be 9 , Use have to chomp , There are only 9 fields inside the pipe

The reason is the use of 'chomp' before the 'split' function.

The perldoc page of split says

When you remove the last '\n', split omits those last empty fields. but it doesn't if you keep it, as you can see in my example.

Regards,
Birei