in reply to How to get the number of fields found by split without a warning?

If you don't want to actually split but just want to know how many fields split would return, try one of the methods illustrated here:
#!perl use strict; use warnings; my $str = "a,b,c,d,e"; my $n = 1 + $str =~ tr/,//; # Field separator is a single char print "$n\n"; $n = 1 + (() = $str =~ /,/g); # Field separator is a regex print "$n\n";

The PerlMonk tr/// Advocate
  • Comment on Re: How to get the number of fields found by split without a warning?
  • Download Code