in reply to Delimeter Count?

Call me crazy, but I'd bet there's some sort of simple relationship between the number of fields and the number of delimiters between them. But then you might have to use that newfangled "Math" stuff . . .

Replies are listed 'Best First'.
Re^2: Delimeter Count?
by Ronnie (Scribe) on Nov 28, 2005 at 15:17 UTC
    The problem with the scalar option and split is that the number of fields is returned not the number of delimeters. The delimeter I was testing for was a pipe (|). Some of my records end with |||||| and some end with |fred|blogs. This produces a different result even if there are the same number of pipes.

      Use -1 as the third argument of split:

      $rec = 'has|trailing|pipes|||'; print(scalar(split(/\|/, $rec )), "\n"); # 3 print(scalar(split(/\|/, $rec, -1)), "\n"); # 6

      Consult perldoc -f split, specifically the discussion of using a negative number as LIMIT.