Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: How to Split on specific occurrence of a comma

by LanX (Sage)
on Dec 03, 2020 at 22:34 UTC ( #11124607=note: print w/replies, xml ) Need Help??


in reply to Re^2: How to Split on specific occurrence of a comma
in thread How to Split on specific occurrence of a comma

Your welcome! :)

on a side note

This

  $line =~ s/^[^=]*\=//;

is IMHO better written as

  my ($var,$list) = split /=/, $line, 2;

It's not only much easier to read and self-documenting, you'll also have a chance to check if $var eq "Teams"

And if $var is of no interest you can also write

  my ( undef, $list ) = split /=/, $line;

debugger demo

DB<211> $line = "Teams=PATRIOTS,BILLS,DOLPHINS,JETS,COWBOYS,GIANTS,E +AGLES,REDSKINS,BENGALS,OILERS,STEELERS,BROWNS,SEAHAWKS,RAMS,49ERS,RAI +DERS" DB<212> x ($var,$list) = split /=/, $line 0 'Teams' 1 'PATRIOTS,BILLS,DOLPHINS,JETS,COWBOYS,GIANTS,EAGLES,REDSKINS,BENGAL +S,OILERS,STEELERS,BROWNS,SEAHAWKS,RAMS,49ERS,RAIDERS'

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

) the 2 in case you are worried that the character "=" appears in your list elements

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2021-10-28 09:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (96 votes). Check out past polls.

    Notices?