Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Question regarding split

by sn1987a (Hermit)
on Jan 20, 2014 at 16:15 UTC ( #1071341=note: print w/replies, xml ) Need Help??

in reply to Question regarding split

Highlighting a different sentence in the section quoted by Anonymous Monk at Re^2: Question regarding split
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.

Just add at LIMIT of -1 to your split. Note: if the last ';' is a terminator instead of a separator, you will have one extra (empty) element at the end of your array:

my @arr = split /;/, $str, -1; # pop @arr; # to drop the last element

Replies are listed 'Best First'.
Re^2: Question regarding split(SOLVED)
by rjohn1 (Sexton) on Jan 21, 2014 at 03:02 UTC

    Beautiful. This is what i wanted.

    Thanks a lot guys...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1071341]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2016-10-23 21:30 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (302 votes). Check out past polls.