user786 has asked for the wisdom of the Perl Monks concerning the following question:
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 : 0
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Regular expressions
by RichardK (Parson) on Apr 10, 2015 at 18:11 UTC | |
Re: Regular expressions
by GotToBTru (Prior) on Apr 10, 2015 at 18:10 UTC | |
by user786 (Sexton) on Apr 10, 2015 at 18:16 UTC | |
by GotToBTru (Prior) on Apr 10, 2015 at 18:19 UTC | |
by Anonymous Monk on Apr 10, 2015 at 19:23 UTC | |
Re: Regular expressions
by NetWallah (Canon) on Apr 10, 2015 at 18:19 UTC | |
Re: Regular expressions
by ww (Archbishop) on Apr 10, 2015 at 20:06 UTC |
Back to
Seekers of Perl Wisdom