Question:
I explain:
print "Введите команду:\n";
chomp ($kom = >STDIN>);
if ($kom = <условие>)
{
оператор 1;
оператор 2;
}
else
{
оператор 3;
}
And so that when any branch is executed, the script continues to wait for the input of the command and, without waiting for the completion of the first one, begins to fulfill the condition of the second one? Thank you.
Answer:
You can start a new process to execute each command entered:
while (<STDIN>) {
chomp();
next if $_ eq '';
last if $_ eq 'exit';
fork() and next;
# тут обрабатываем введённую команду
exit();
}
If, at the end of the input loop, you need to wait for the processing of all entered commands, you can do this:
use POSIX ':sys_wait_h';
my %children;
while (<STDIN>) {
chomp();
next if $_ eq '';
last if $_ eq 'exit';
my $pid = fork();
if ($pid) {
$children{$pid} = 1;
next;
}
# тут обрабатываем введённую команду
exit();
}
# ждём окончания всех процессов обработки
while (keys(%children)) {
for (keys(%children)) {
my $ret = waitpid($_, WNOHANG);
next unless $ret;
delete($children{$_}) if $ret != -1;
}
}