in reply to Split a string with multiple trailing delimeters?
If LIMIT is specified and positive, it represents the maximum number of fields the EXPR will be split into, though the actual number of fields returned depends on the number of times PATTERN matches within EXPR. If LIMIT is unspecified or zero, trailing null fields are stripped (which potential users of pop would do well to remember). If LIMIT is negative, it is treated as if an arbitrarily large LIMIT had been specified. Note that splitting an EXPR that evaluates to the empty string always returns the empty list, regardless of the LIMIT specified.
So my @values = split(/\*\*/,$str,-1); returns:
$VAR1 = [ '123', 'abc', '', '', '' ];
Note you have a trailing entry, hence 3 empty strings not 2.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Split a string with multiple trailing delimeters?
by haolecoder (Initiate) on Jan 04, 2011 at 18:59 UTC |