Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by dirtdog (Monk)
on Dec 03, 2020 at 22:07 UTC ( #11124604=note: print w/replies, xml ) Need Help??


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

I think this approach should work. thanks!

  • Comment on Re^2: How to Split on specific occurrence of a comma

Replies are listed 'Best First'.
Re^3: How to Split on specific occurrence of a comma
by LanX (Sage) on Dec 03, 2020 at 22:34 UTC
    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://11124604]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2021-10-18 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (72 votes). Check out past polls.

    Notices?