Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Sub Routine calls

by mrras25 (Acolyte)
on Nov 18, 2009 at 04:37 UTC ( #807856=perlquestion: print w/ replies, xml ) Need Help??
mrras25 has asked for the wisdom of the Perl Monks concerning the following question:

This is probably simple but I am not able to wrap my head around this one -

I have a subroutine that checks to see if a status is 0 yet - what I would like is loop through until the status returns 0. How would I do this?

# Code to loop sub routine checkCopyStat ????? #sub routine sub checkCopyStat { my $clTyp = shift; $status = 0; open OUT, ">/usr/local/emc/bin/temp.txt" or die "unable to open fil +e: $! \n"; my $name = "LUN 120 DB"; # for test purposes my $navicmd = `naviseccli -address $spa -user $nviusr -password $nv +ipwd -scope global clone -listclone -Name "$name" -cloneid $copies{$c +lTyp} -Clonestate -PercentSynced`; print OUT "$navicmd"; #put contents into a temporary file close(OUT); open FILE, "< /usr/local/emc/bin/temp.txt" or die "unable to open f +ile: $! \n"; my %hash; while (<FILE>) { my ($col1, $col2) = (split /:/, $_)[0,1]; chomp($col1,$col2); if(!$col1) {next;} if(!$col2) {next;} $hash{$col1} = $col2 } foreach my $key(%hash) { if($hash{'CloneState'} =~ /Consistent/) { $status = 0; }elsif($hash{'CloneState'} =~ /Synchronizing/) { $status = $hash{'PercentSynced'}; } else { print "State Unknown for clone\n"; $status = -1; } } close(FILE); unlink('/usr/local/emc/bin/temp.txt'); return($status); }

Comment on Sub Routine calls
Download Code
Replies are listed 'Best First'.
Re: Sub Routine calls
by gmargo (Hermit) on Nov 18, 2009 at 05:03 UTC

    Am I misunderstanding your question? Just a simple loop to check for zero?

    while (checkCopyStat() != 0) { sleep 5; }

    Look out for that foreach over the hash - you don't need it.

      Nope you guys were not misunderstanding - this is what a week of coding non-stop with the flu will do for you. Once you guys replied back with it, I went ahead and put foot into mouth - SWEET CHEESE I need some sleep! Thank you all for the help!
        At least you're not trying to write css :) position:absolute; display:inline; width: 100% 80% 40em 120em 20em;

        What do you think this is, Python?
Re: Sub Routine calls
by colwellj (Monk) on Nov 18, 2009 at 04:59 UTC
    you can try something like this
    If you want your script to do something else meanwhile you will need to fork
Re: Sub Routine calls
by Jenda (Abbot) on Nov 18, 2009 at 12:31 UTC

    There is no reason to use a temporary file. Just assign the results of the `naviseccli ...` into an array and loop through that array. Just replace the

    my $navicmd = `naviseccli -address $spa -user $nviusr -password $nvipw +d -scope global clone -listclone -Name "$name" -cloneid $copies{$clTy +p} -Clonestate -PercentSynced`;
    my @navicmd = `naviseccli -address $spa -user $nviusr -password $nvipw +d -scope global clone -listclone -Name "$name" -cloneid $copies{$clTy +p} -Clonestate -PercentSynced`;
    remove all the file fiddling and replace
    while (<FILE>) {
    foreach (@navicmd) {
    You might also want to rename that variable, because it doesn't contain any command, but rather the output or results of some command.

    Enoch was right!
    Enjoy the last years of Rome.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2015-10-10 15:49 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (257 votes), past polls