Answers for "perl exit loop"

1

perl exit loop

# Basic syntax:
last;
# Where last is analogous to break in Python, Bash, R, etc

# Example usage:
for my $i (0 .. 5) {
	print "index is $i\n";
    # Exit the for loop if the index equals 3
	if ($i == 3) {
		last;
    }
}
Posted by: Guest on March-03-2022
0

perl exit loop example

my $counter = 1;
foreach $foo (sort {$importHash{$b} <=> $importHash{$a}} (keys %importHash))
{
  # push the string $foo onto the @tags array
  push @tags, $foo;
  
  # break out of our perl loop when the counter reaches 10
  last if ($counter++ == 10);
}
Posted by: Guest on October-10-2021

Browse Popular Code Answers by Language