> > spaces before and after
the spaces before are IMHO best dealt by stripping them before splitting. °
$line =~ s/^\s+//;
Even your pseudo python code can't do this in a one-liner with split (IMHO).
But more importantly your definition of "field" is fuzzy now.
- how do you allow empty fields?
- are all whitespace characters as separator allowed (like tab...)?
- are multiple whitespace characters as separator allowed?
provided there are no "empty fields" and "multiple whitespaces" are allowed as separators:
You can use a regex like /(\S+)/g ( \S is non-whitespace, the opposite of \s)
DB<35> $line = " a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 \n"
DB<36> x ($line =~ /(\S+)/g)[0,1,3,5,7,9]
°) or by using the magic of ' ' soonix showed us here.
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>
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
Want more info? How to link
or How to display code and escape characters
are good places to start.