Conditional Branching in Perl?
Conditional Branching in Perl?
(OP)
Greetings!
Well, I dug myself in over my head with a basic syntax debacle in Perl for my Linux box.
Here's the code sample which I wish to fix:
Simply, this code is to lurk in the background until "some-process" is running on the system, pop a warning box at that point, stand by after the user clicks "OK", and then lurk again until the next round.
All "goto" style matters aside, where might I have missed the mark syntaxwise in this rustic example? Of course, any help is thoroughly appreciated...
Thanks so much!
Well, I dug myself in over my head with a basic syntax debacle in Perl for my Linux box.
Here's the code sample which I wish to fix:
CODE --> Perl
#!/usr/bin/perl
$value = '$(pgrep some-process | wc) -gt 0';
TEST:
if ($value)
{
sleep 2;
zenity --warning --text="some-process is running.";
goto STANDBY;
}
else
{
goto TEST;
}
STANDBY:
if ($value)
{
goto STANDBY;
}
else
{
goto TEST;
} Simply, this code is to lurk in the background until "some-process" is running on the system, pop a warning box at that point, stand by after the user clicks "OK", and then lurk again until the next round.
All "goto" style matters aside, where might I have missed the mark syntaxwise in this rustic example? Of course, any help is thoroughly appreciated...
Thanks so much!





RE: Conditional Branching in Perl?
Considering pgrep a little more, would something like this work just as well (or better):
CODE --> Perl
???
RE: Conditional Branching in Perl?
One problem might be that the loop:
STANDBY:
if ($value)
{
goto STANDBY
}
is infinite once $value is true. You probably want to re-evaluate $value once per loop (with some appropriate sleep to slow things down).
But I'm just guessing. Again, what's the problem you're having?
RE: Conditional Branching in Perl?
Thanks for stopping by! Sorry to be away so long.
Evaluating the $value variable was part of the problem. As a throwback from my OO days, I thought the variable would be reevaluated without direct placement. Thanks for the heads up.
Here's one back!
CODE --> Perl
from the OP code should read
CODE --> Perl
to enable that code segment to pass through Perl and execute as bash. Life is full of these cute little things...
While I've got you here, how does one express a value representing a fraction of a second in Perl's sleep method? Couldn't find anything which made ready sense...
Thanks again, and have a great weekend ;)
RE: Conditional Branching in Perl?
Best you have a look there first so we don't end up duplicating the manual in this forum.
RE: Conditional Branching in Perl?
To varying degrees of context/scope, this could be said of most queries posted throughout Eng-Tips.
Thank you for sharing your expertise.
Good day.