Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to Split on specific occurrence of a comma

by tybalt89 (Prior)
on Dec 03, 2020 at 22:08 UTC ( #11124605=note: print w/replies, xml ) Need Help??


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

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11124600 use warnings; my $line; my @teams; while ( $line = <DATA> ) { chomp $line; if ($line =~ /^#/ || $line =~ /^\s*$/) { next; } $line =~ s/^[^=]*\=//; push @teams, map [ split /,/ ], "$line," =~ /((?:.*?,){1,3})/gx; } use Data::Dump 'dd'; dd \@teams; __DATA__ Teams=PATRIOTS,BILLS,DOLPHINS,JETS,COWBOYS,GIANTS,EAGLES,REDSKINS,BENG +ALS,OILERS,STEELERS,BROWNS,SEAHAWKS,RAMS,49ERS,RAIDERS

Outputs:

[ ["PATRIOTS", "BILLS", "DOLPHINS"], ["JETS", "COWBOYS", "GIANTS"], ["EAGLES", "REDSKINS", "BENGALS"], ["OILERS", "STEELERS", "BROWNS"], ["SEAHAWKS", "RAMS", "49ERS"], ["RAIDERS"], ]

Log In?
Username:
Password:

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

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







    Results (96 votes). Check out past polls.

    Notices?