Perl Warts

misfeatures and other problems
PERL| PHP| PYTHON| RUBY
Answers: (all questions)
(question)
Question:
#!/usr/bin/perl

foreach $x (1,2,3,4,5) {
  print "x: $x\n";
  if ($x > 2) { print "break\n"; break; }
}
Answer:
The program prints:
x: 1
x: 2
x: 3
break
x: 4
break
x: 5
break
The break operator does not do the same thing as in C or Python. Use last instead. Similarly, use next instead of continue.
PERL| PHP| PYTHON| RUBY
Last modified: March 30, 2006 @ 6:47 MST
Copyright (C) 1996-2024 Selene ToyKeeper