in reply to Re: Delimeter Count?
in thread Delimeter Count?

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.

Replies are listed 'Best First'.
Re^3: Delimeter Count?
by ikegami (Patriarch) on Nov 28, 2005 at 15:32 UTC

    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
Re^3: Delimeter Count?
by Fletch (Bishop) on Nov 28, 2005 at 15:34 UTC

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