Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
my $spooler = `lpstat -r`; if ( $spooler = "scheduler is not running" )
You're assigning to $spooler in your conditional statement (not just the backtick statement). You really should be comparing, or pattern-matching.
if ( $spooler eq "scheduler is not running" ) ... if ( index($spooler, "scheduler is not running") >= 0 ) ... if ( $spooler =~ /scheduler is not running/ ) ...
Given that this is output from some other tool, I would guess that the last of those alternatives is the most useful.

Update: After re-reading your question as posed, I guess I'll state what I thought was obvious-- I rarely want to assign (use the = operator) in a conditional statement. To compare numbers, you don't assign, you check for equality with the == operator. To compare strings, you don't assign, you check for equality with the eq operator. Also, the command output captured with backticks contains ALL of the standard output, newlines and all, so if your scheduler command really does JUST print "scheduler is not running", it STILL likely won't match exactly with the eq operator.

--
[ e d @ h a l l e y . c c ]


In reply to Re: Backticks and Pattern Matching. by halley
in thread Backticks and Pattern Matching. by misconfiguration

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 01:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found