Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Set condition only if array becomes empty

by virtualsue (Vicar)
on Sep 27, 2017 at 09:23 UTC ( #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.
  • Comment on Re: Set condition only if array becomes empty

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2019-11-18 19:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (91 votes). Check out past polls.

    Notices?