in reply to Re: (jeffa) 3Re: More Variable length regex issues
in thread More Variable length regex issues
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)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (jeffa) 5Re: More Variable length regex issues
by dextius (Monk) on Jun 09, 2003 at 05:14 UTC | |
by thor (Priest) on Jun 09, 2003 at 05:30 UTC | |
by BrowserUk (Patriarch) on Jun 09, 2003 at 09:48 UTC | |
by thor (Priest) on Jun 09, 2003 at 12:28 UTC | |
by BrowserUk (Patriarch) on Jun 09, 2003 at 12:59 UTC | |
by dextius (Monk) on Jun 09, 2003 at 19:12 UTC | |
| |
by jeffa (Bishop) on Jun 09, 2003 at 07:42 UTC |