in reply to Re: Working of split
in thread Working of split

Ups... right. Well there is a name and 4 tabs. And return value is just one cell (name), no empty ones are returned. How can i change it so that it returns empty ones as well?

Replies are listed 'Best First'.
Re: Working of split
by Abigail-II (Bishop) on Feb 05, 2004 at 12:09 UTC
    So, I guessed right. I also mentioned something about the number of arguments of split. Why don't you consult its manual page, and come back only if the manual page isn't clear?

    Abigail

      Yes, is spotted it now... *reading*
      So -1 (any negative number) in limit in split will return all the empty trailing columns. Sometimes i feel like an braindead :P. Huoh.
Re: Re: Re: Working of split
by podian (Scribe) on Feb 05, 2004 at 20:47 UTC
    well, for me, it returned the correct number:

    1 'name

    '

    3 'name

    '

    3 'name val val

    '

    This is what I had the data file: name

    name

    name val val

    firt one is just the name

    second one is name and two tabs

    third line also has two tabs

    Here is your code with while loop

    #!/usr/bin/perl # # testing split # use warnings; use strict; while (<>) { my @a=split (/\t/,$_); my $val=scalar (@a); print "$val '@a'\n"; }