Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Persistent counter

by Tuna (Friar)
on Aug 19, 2001 at 00:04 UTC ( #105945=perlquestion: print w/replies, xml ) Need Help??

Tuna has asked for the wisdom of the Perl Monks concerning the following question:

< Tuna scrathces his head>

In my program, I execute a subroutine N times. This subroutine calls external programs, which return either 0 or 1. I need to keep track of how many times "" fails. If it fails > 2x, I will enter another sequence of subroutines.

Here's an example:

## In main, I initialize, my $failedActivation = 0; sub activateFirstCluster { my $offlineStatus; if ($failedActivations eq 3 ) { $offlineStatus = &executeTaskSequence($clusterHost, @offLineSequence); } else { $command = "/bin/ls"; ($error = &runSystemCommand($command)) && $failedActivations++; print "failed $failedActivations times\n"; return $success; } }
If I inject an obvious error into the subroutine, such as rename $command to "/bin/lssss", my print statement still prints 0. Any ideas?

Replies are listed 'Best First'.
Re: Persistent counter
by nehlwyn (Acolyte) on Aug 19, 2001 at 01:16 UTC

    Greetings fellow monk ,

    do you "use strict" ?

    I'm not sure , i see at first a weird if ($failedActivations eq 3 ) , it should be if ($failedActivations == 3 ) or if ($failedActivations eq "3" )

    i think you should have an error message at least from that . Try to use strict ('helps a lot !!! as well as perl -w ) and give us some news of what happens in a reply to your question ...

    the little one.
Re: Persistent counter
by Tuna (Friar) on Aug 19, 2001 at 01:19 UTC
    I do use strict, as well as warnings. Ya wanna know what my problem was?
    I assigned $command the value, "/bin/l". Guess what my system alias for "ls" is?
Re: Persistent counter
by little (Curate) on Aug 19, 2001 at 15:17 UTC
    use warnings; # or the -w switch
    then you would have gotten an error telling you that
    my $failedActivation = 0;
    was only used once, (possible typo?) as you refer to it later mistakenly by

    Have a nice day
    All decision is left to your taste

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://105945]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2022-05-26 10:24 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (93 votes). Check out past polls.