I am doing some evaluating on a variable,
$Fw_Ip = %x[/usr/bin/plink -pw xxxxxx [email protected] “command” |grep
Now I want to do something depending on if the $Fw_Ip is empty or not.
if ($Fw_Ip != nil)
I guess that the variable is not empty so it will always return True but
if I puts $Fw_Ip it is empty.
Suggestions on how to solve it would be much appreciated.
nil != “”
Your command will always return something, even if it’s just an empty
string. Replace the check to nil with “” and it should work. Also, two
- Don’t use $variable variable names unless you absolutely need to,
these are global and make Ruby look like Perl. Also don 't start a
variable name with a capital letter, this denotes a constant. I’d rename
your $Fw_Ip variable to fw_ip
- If you wanted to check for nil, I’d highly recommend the much cleaner
looking “variable.nil?” syntax, which is also more ruby-esque.
Hope this helps,
Thank’s Ryan it worked perfectly with “” . I will adjust my code to not
use global variable since like you say I dont need it, somehow I have
always used it bad habit I guess.
Thanks once again.