http://qs1969.pair.com?node_id=11141174


in reply to Extracting selected fields form file record

ehm ...

> > 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.

Please clarify

update

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)

Debugger demo:

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] 0 'a0' 1 'a1' 2 'a3' 3 'a5' 4 'a7' 5 'a9' DB<37>

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

update

°) or by using the magic of ' ' soonix showed us here.