I have written a Perl script which parses the output of a command, looks for the task name in the command output and prints the task name.
Command output looks like the below
Here task name is 'mutipleregexpression'. But part of the word 'pression' gets printed in the new line.
Task Name: multipleregex
pression
This is the regex that im currently using in my code:
`$line =~ /(.*):\s*(.+)/`
The above regex doesn't capture part of the task name that gets printed in the new line. It only captures 'multipleregex' it doesn't capture 'pression' since pression gets printed in the new line. i see the following error
Use of uninitialized value $result in concatenation (.) or string at line 114.
So my question is what is the change that i need to make to the regularexpression so that it captures 'pression' as well
function for capturing the task name
sub get_status {
my ($self) = @_;
my $taskname;
my %result;
my $line;
$self->{'cmd'} = # command goes here;
# execute the command
$self->execute($self->{'cmd'});
$self->{'stdout'} = $self->get_stdout();
my $count = 0;
# traverse through the output to parse the output
foreach $line (@{ $self->{'stdout'} }) {
chomp $line;
if ( $line =~ m/^Task\sName\:\s+(\w+)/msx ) {
$taskname = $1;
$count = 0;
}
elsif ($line =~ /(.*):\s*(.+)/) {
my $key = $1;
my $value = $2;
$result{$taskname}{ ++$count } = $value;
}
}
return \%result;
}
Function call :
my $result = $stats->get_status('multipleregexpression', '1');
INFO('Status of the task is :' . $result );
Output :
Use of uninitialized value $result in concatenation (.) or string at line 114.
20150317T194029 INFO Status of the task is :