Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^6: How to split

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

in reply to Re^5: How to split
in thread How to split

Adventures in regular expressions, part 7, readability

#!/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; #~ my( $prefix, @biscuits ) = $bottom =~ /(^\s+\S+|[^\s\(,]+\([^\s\)]+ +\))/g; my( $prefix, @biscuits ) = $bottom =~ m{ ( # $1 ^\s+\S+ # prefix | [^\s\(,]+ \( [^\s\)]+ \) ) # $1 }xsmg; dd \$prefix, \@biscuits ; for my $tack ( @biscuits ){ print "$prefix $tack\n"; } __END__ $ perl shineon007 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://993412]
[stevieb]: I'm learning that no matter how good a piece of software is at what it's supposed to do, it's a piece of shit without providing any API documentation. (Talking about C++ here currently). Seriously... write software for an embedded platform and make...
[stevieb]: guess based on the sparse examples, and the header files that are spread out illogically?
[stevieb]: document the public facing functions/methods people... ALL OF THEM.

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2017-05-28 23:45 GMT
Find Nodes?
    Voting Booth?