Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Question regarding split

by sn1987a (Monk)
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


Comment on Re: Question regarding split
Download Code
Re^2: Question regarding split(SOLVED)
by rjohn1 (Acolyte) on Jan 21, 2014 at 03:02 UTC

    Beautiful. This is what i wanted.

    Thanks a lot guys...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2014-12-28 04:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (178 votes), past polls