Subject: | could not load lines from scalar variable |
Greetings,
I was trying to use the distribution Test-Parser-Vmstat to parse a
vmstat output, which in case is based in Test-Parser.
I was supplying Test-Parser-Vmstat object a scalar variable with the
content of a vmstat output (a small amount of data) and got several
warnings about dealing with "undefined" content in
Test::Parser::Vmstat::parse_line, which is a override version of
Test::Parser::parse_line.
I got a bug in Test::Parser::parse that was not returning the line in
the while block.
I just replaced the code with a foreach statement:
# If it's a scalar and has newlines, it's probably the full text
elsif (!ref($input) && $input =~ /\n/) {
my @lines = split /\n/, $input;
foreach my $line(@lines) {
#while (shift @lines) {
$retval = $self->parse_line($line) || $retval;
last if $retval == END_OF_RECORD;
}
Everything worked fine after that. BTW, this implementation can be quite
dangerous if a large amount of data is passed.