When i am running this command *service mysql start* at command line it gives OK but when calling it in perl script it print *$mysqld: unrecognized service* in the output file. Therefore the variable result gets NOK and it prints NOK. This does not work because it should print OK.
On Wed, Aug 19, 2009 at 3:24 PM, Chas. Owens <chas.ow...@gmail.com> wrote: > On Wed, Aug 19, 2009 at 08:59, Raheel Hassan<raheel.has...@gmail.com> > wrote: > snip > > written thsi code, but the result of the command is not saving in the > file , > > any suggestions please. > snip > > my $result = 'service mysql start 2>>/var/log/comm.log'; > snip > > Your are using '' which is the single quoted string (i.e. > non-interpolating string), you mean to use `` which is the [command > execution string][1]. I would advise against using backticks for this > very reason. Use the generalized form instead: qx//. The slashes may > be replaced with any pair of characters, or in the case of bracketing > characters, the opposite bracketing character: > > my $result = qx{service mysql start 2>>/var/log/comm.log}; > > snip > > if($result =~ /OK/) > snip > > You also may want to use the [word-boundary zero-width assertion > (\b)][2] to ensure that you are matching the word OK not the substring > OK in a larger word like LOOK: > > if ($result =~ /\bOK\b/) > > [1] : http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators > [2] : http://perldoc.perl.org/perlre.html#Assertions > > Chas. Owens > wonkden.net > The most important skill a programmer can have is the ability to read. >