in reply to Count Using Split

 print $#tt; should probably be  print scalar @t; instead.

Replies are listed 'Best First'.
Re^2: Count Using Split
by jethro (Monsignor) on Sep 17, 2008 at 17:58 UTC
    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;
      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;