Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Question regarding split

by sn1987a (Chaplain)
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 avoiding work at the Monastery: (3)
As of 2019-04-20 08:12 GMT
Find Nodes?
    Voting Booth?
    I am most likely to install a new module from CPAN if:

    Results (108 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!