They both achieve the same results, and guess which one is easier to understand?my $str = 'foo,bar,moo,cow'; my @value = $str =~ m/(\w+)\,?/g; print "@value\n"; @value = split(',',$str); print "@value\n"
You say have non-repeatable fields, how does using a regex make this easier than split? What do you think split uses to split? A regex! Besides, oro has a family of split functions. You could always do a series of splits if multiple delimiters are used:
The split functions found in the org.apache.oro package can do this, you just have to jump through more hoops. ;) Not that it matters, but one of my beefs about Java is not being able to process lists easily like you can in Perl:my $str = 'a,b,c:d,e,f:g,h,i'; my @part = split(':',$str); foreach my $part (@part) { my @subpart = split(',',$part); print "@subpart\n"; }
Best of luck.print $_,$/ for map split(',',$_), split(':', $str);
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In reply to (jeffa) 5Re: More Variable length regex issues
by jeffa
in thread More Variable length regex issues
by dextius
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |