in reply to Re: Count Using Split
in thread Count Using Split

No, because if one occurence of the search string is found, the string is split into two. So your code would print 2 when it should print 1. Since I don't like the $# syntax either, I would use print @t-1;

Replies are listed 'Best First'.
Re^3: Count Using Split
by jwkrahn (Abbot) on Sep 17, 2008 at 18:23 UTC
    No, because if one occurence of the search string is found, the string is split into two.

    Then  my @t=split(/mapping id="/,$_); should be  my @t = /mapping id="/g; instead.

        :-)

      Having an array of identical elements is rather useless. The only thing you can do is count them. Why not get the count from the start.
      my $t = () = /mapping id="/g;