I have written a function which is in a library, and I call the functions from my test script.
The function returns 0.
ideally it should return Starting strongSwan 5.1.2 IPsec
I checked the regular expression in https://regex101.com/ . My regex seems to be correct. /(Starting strongSwan.*IPsec$)/ .
Can somebody help me out with the return value of the function.
Function :
sub ipsec_restart { my ($self) = @_; my $cmd = 'sudo -s ipsec restart'; my $restart = 0; $self->execute($cmd); foreach my $line ( @{ $self->get_stdout() } ) { if ( $line =~ /(Starting strongSwan.*IPsec$)/ ) { $restart = $1; last; } } return $restart; }
Function call :
$self->{'ipsec_restart'} = $self->{'ipsec_obj'}->ipsec_restart(); ('[Startup] ipsec restart status is : ' . $self->{'ipsec_res +tart'} );
Expected output : See the highlighted text below.
Starting strongSwan 5.1.2 IPsec Actual output is : 0In reply to Regular expressions by user786
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |