Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Set condition only if array becomes empty

by virtualsue (Vicar)
on Sep 27, 2017 at 09:23 UTC ( [id://1200181]=note: print w/replies, xml ) Need Help??


in reply to Set condition only if array becomes empty

You already have valuable hints in this thread. Make sure you strip or check for a newline at the end of the lines that your 'cmd'or 'get_response' returns, unless they already do that. It's easy to forget this (I often do). Either
chomp($output)
or
if ($output eq "3000\n")
should work. If it doesn't, searching for newline removal here and on the web will come up with a lot of discussion about it. Some ways to check if an array is empty:
    if (! @array) {}
 
    if (scalar(@array) == 0) {}
In the code you showed us, you might just check if $output is "" or whatever happens when you run $rh->get_response on a command that didn't provide any output. I also would be curious as to where the "3000" came from as it sounds like a magic number, but for all I know that's guaranteed to be fine for the entire lifetime of your script.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1200181]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-28 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found