in reply to Loop Control - First?

The outer block doesn't need to be a loop; a plain block is sufficient:
ATTEMPT: { COMMAND: foreach my $CommandHsh (@{$command_section}){ $Result = $self->ExecuteCommand($CommandHsh); if ($Result eq "END"){ $self->{_logfile}->debug("Signal received to END command secti +on"); last COMMAND; } elsif ($Result eq "CONTINUE"){ $self->{_logfile}->debug("Signal received to CONTINUE command +section"); next COMMAND; } elsif ($Result eq "RESTART"){ $self->{_logfile}->debug("Signal received to RESTART command s +ection"); redo ATTEMPT; } else { $self->{_logfile}->error("Incorrect exit type from ExecuteComm +and"); } } $self->{_logfile}->info("End of CommandSection"); }

Replies are listed 'Best First'.
Re: Loop Control - First?
by Abigail-II (Bishop) on Oct 28, 2003 at 16:39 UTC
    The outer block doesn't even need to exist. If you use a goto, the solution will be more symmetric (yeah, getting more pleasing looking code by using goto!):
    COMMAND: foreach my $CommandHsh (@{$command_section}){ $Result = $self->ExecuteCommand($CommandHsh); if ($Result eq "END"){ $self->{_logfile}->debug("Signal received to END command secti +on"); last COMMAND; } elsif ($Result eq "CONTINUE"){ $self->{_logfile}->debug("Signal received to CONTINUE command +section"); next COMMAND; } elsif ($Result eq "RESTART"){ $self->{_logfile}->debug("Signal received to RESTART command s +ection"); goto COMMAND; } else { $self->{_logfile}->error("Incorrect exit type from ExecuteComm +and"); } } $self->{_logfile}->info("End of CommandSection");

    Abigail