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

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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11124602]
help
Chatterbox?
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
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (90 votes). Check out past polls.

    Notices?