You keep on using that word 'split' ... i do not think
you know what it means. ;) Consider the following:
my $str = 'foo,bar,moo,cow';
my @value = $str =~ m/(\w+)\,?/g;
print "@value\n";
@value = split(',',$str);
print "@value\n"
They both achieve the same results, and guess which one is
easier to understand?
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:
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";
}
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:
print $_,$/ for map split(',',$_), split(':', $str);
Best of luck.
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)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.