in reply to Re: How to split
in thread How to split
Adventures in regular expressions
#!/usr/bin/perl -- use strict; use warnings; use Data::Dump; my $blah = ' VAR DS 0D DC AL1(045),AL2(286),AL2(117),AL2(290)'; my ( $top, $bottom ) = split /[\r\n]+/, $blah; print "$top\n"; #~ my( $prefix, @biscuits ) = grep length, split /[\s,]+/, $bottom; my( $prefix, @biscuits ) = split /(?:(?<!^)\s+)|,/, $bottom; dd \$prefix, \@biscuits ; for my $tack ( @biscuits ){ print "$prefix $tack\n"; } __END__ $ perl shineon001 VAR DS 0D (\" ", ["DC", "AL1(045)", "AL2(286)", "AL2(117)", "AL2(290)"]) DC AL1(045) AL2(286) AL2(117) AL2(290)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How to split
by Anonymous Monk on Sep 13, 2012 at 08:01 UTC | |
by Anonymous Monk on Sep 13, 2012 at 08:02 UTC | |
by Anonymous Monk on Sep 13, 2012 at 08:03 UTC | |
by Anonymous Monk on Sep 13, 2012 at 08:05 UTC |