Text::ParseWords::parse_line bug?

T

tsotsi

Does anyone know of any bug in ParseWords? I have an input string that
I want to split on the pipe using ParseWords since split removes
trailing pipes with empty data.

code
---------------------------------------------------------------------------------------------------------------------
use Text::parseWords;

open(INPUT,"testdata.txt");

while (<INPUT>)
{
chomp;
my @fields = Text::parseWords::parse_line( qr(\|), 0,$_);
print "==$_==\n";
print "field0=$fields[0]\n";
print "field1=$fields[0]\n";
print "field2=$fields[0]\n";
print "field3=$fields[0]\n";
}

close(INPUT);

---------------------------------------------------------------------------------------------------------------------

I get the following when I run it

---------------------------------------------------------------------------------------------------------------------
perl qwe.pl
==641.59 $' 19|641.59 B|TX725.H1
B49|-|1364|1|DEAN|1|TOWN|COOK|0|0|19971126|641.59 B|==
field0=
field1=
field2=
field3=
 
X

xhoster

tsotsi said:
Does anyone know of any bug in ParseWords? I have an input string that
I want to split on the pipe using ParseWords since split removes
trailing pipes with empty data.

Split only does that if you don't supply a nonzero 3rd argument. So supply
a negative 3rd argument.

Text::parseWords doesn't split at delimiters that are inside quotes.
In your case, all the delimiters are inside (techincal, after an
unbalanced) quote.

Xho
 
A

anno4000

tsotsi said:
Does anyone know of any bug in ParseWords? I have an input string that
[...]

while (<INPUT>)
{
chomp;
my @fields = Text::parseWords::parse_line( qr(\|), 0,$_);
print "==$_==\n";
print "field0=$fields[0]\n";
print "field1=$fields[0]\n";
print "field2=$fields[0]\n";
print "field3=$fields[0]\n";
}

Apart from Xho's remarks, did you notice you are printing the
same field four times? Talk about bugs...

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top