Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Backticks and Pattern Matching.

by halley (Prior)
on Feb 05, 2008 at 15:30 UTC ( #666318=note: print w/replies, xml ) Need Help??

in reply to Backticks and Pattern Matching.

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 ]

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://666318]
[Corion]: thezip: The Canary Islands - they have a constant climate
[Corion]: Maybe a bit too many old people, but for some do-nothing vacation for R&R exactly the right thing ;)=
[thezip]: That's awesome. I bet you feel totally rejuvenated and ready for the next thing.

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2017-02-23 17:07 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (349 votes). Check out past polls.