Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: How to Split on specific occurrence of a comma

by swl (Vicar)
on Dec 03, 2020 at 21:35 UTC ( #11124602=note: print w/replies, xml ) Need Help??

in reply to How to Split on specific occurrence of a comma

The limit arg to split lumps the rest of the string into the last array entry. If you want n items, then split with a limit of n+1 and ignore or discard the last entry in the array.

Your code was also using a map to create an array ref, which is not needed here.

This updated snippet from your example code will give an array of two items:

@teams = split /,/, $line, 3; pop @teams;

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2021-10-26 06:34 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (90 votes). Check out past polls.