Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: How to split

by Anonymous Monk
on Sep 13, 2012 at 07:58 UTC ( #993407=note: print w/ replies, xml ) Need Help??


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)


Comment on Re^2: How to split
Download Code
Re^3: How to split
by Anonymous Monk on Sep 13, 2012 at 08:01 UTC

    Adventures in regular expressions, part 2

    #!/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; my( $prefix, @biscuits ) = split /(?:(?<!^)\b\s+)|,/, $bottom; dd \$prefix, \@biscuits ; for my $tack ( @biscuits ){ print "$prefix $tack\n"; } __END__ $ perl shineon002 VAR DS 0D ( \" DC", ["AL1(045)", "AL2(286)", "AL2(117)", "AL2(290)"], ) DC AL1(045) DC AL2(286) DC AL2(117) DC AL2(290)

      Adventures in regular expressions, part 4

      #!/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; #~ my( $prefix, @biscuits ) = split /(?:(?<!^)\b\s+)|,/, $bottom; #~ my( $prefix, @biscuits ) = split /(?:(?<!\A)\b\s+)|,/, $bottom; my( $prefix, @biscuits ) = $bottom =~ /(^\s+\S+)|([^\s\(]+\([^\s\)]+\) +)/g; dd \$prefix, \@biscuits ; for my $tack ( @biscuits ){ print "$prefix $tack\n"; } __END__ $ perl shineon004 Use of uninitialized value $tack in concatenation (.) or string at shi +neon004 line 20. Use of uninitialized value $tack in concatenation (.) or string at shi +neon004 line 20. Use of uninitialized value $tack in concatenation (.) or string at shi +neon004 line 20. Use of uninitialized value $tack in concatenation (.) or string at shi +neon004 line 20. Use of uninitialized value $tack in concatenation (.) or string at shi +neon004 line 20. VAR DS 0D ( \" DC", [ undef, undef, "AL1(045)", undef, ",AL2(286)", undef, ",AL2(117)", undef, ",AL2(290)", ], ) DC DC DC AL1(045) DC DC ,AL2(286) DC DC ,AL2(117) DC DC ,AL2(290)

        Adventures in regular expressions, part 5

        #!/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; #~ my( $prefix, @biscuits ) = split /(?:(?<!^)\b\s+)|,/, $bottom; #~ my( $prefix, @biscuits ) = split /(?:(?<!\A)\b\s+)|,/, $bottom; #~ my( $prefix, @biscuits ) = $bottom =~ /(^\s+\S+)|([^\s\(]+\([^\s\)] ++\))/g; my( $prefix, @biscuits ) = $bottom =~ /(^\s+\S+|[^\s\(]+\([^\s\)]+\))/ +g; dd \$prefix, \@biscuits ; for my $tack ( @biscuits ){ print "$prefix $tack\n"; } __END__ $ perl shineon005 VAR DS 0D ( \" DC", ["AL1(045)", ",AL2(286)", ",AL2(117)", ",AL2(290)"], ) DC AL1(045) DC ,AL2(286) DC ,AL2(117) DC ,AL2(290)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2014-08-31 06:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls