Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

perl
communitycreator

What is redo in Perl?

okwudili onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

redo in Perl is an operator that restarts from the given label without evaluating a conditional statement. When redo is called, no other statements will execute.

When a label is given along with the redo operator, then the execution starts from the loop specified by the label.

Syntax

redo Label

Parameters

The parameter redo takes is the label. The label is assigned to a loop or block of code to be executed.

Example 1

The code below demonstrates the use of redo. The WHATEVER loop will redo even when the condition if($a < 10) tells it to stop, i.e., when $a becomes 10.

# While making exercises "package Test;" needs to be the first line of code.
    
    $a = 1;
  
# Assigning label to loop
OURLABEL: {
   $a = $a + 5;
   redo OURLABEL if ($a < 10);
}
  
# Printing the value
print ($a);

Example 2

We use the redo operator to redo a while loop. The loop will redo when $a is 100, even when the condition if($a < 100) is set.

# While making exercises "package Test;" needs to be the first line of code.

$a = 1;
  
# Assigning label to loop
$count = 1;
OURLABEL: while($count < 10) {
   $a = $a + 5;
   $count++;
   redo OURLABEL if ($a < 100);
}
  
# Printing the value
print ("$a $count");

RELATED TAGS

perl
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring