I've found that if you have a loop like this
$i = 0;
do {
print "$i ";
last if $i == 3;
++$i;
} while ($i != 10);
you will get the run-time error 'Can't "last" outside a loop block' when $i reaches 3.
Putting the 'last' in a proper if() {} block doesn't make any difference.
Apparently this occurs because do { } is just a grouping block, not a looping one, and the while here is the statement modifier while, not the control structure while. do { } is what you use if you want to put a statement modifier on a block of statements - { } alone just won't 'do'.
While that makes a sort of sense, a big red warning in Programming Perl would have helped. 'Do not use! Useful construct merely simulated!'
Additionally: what makes this really dangerous is that, if it occurs in a sub called from within a genuine while, the last will immediately jump out of the genuine loop (even if that loop's in a different scope) without any error or warning message. DO NOT USE.
Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.
Quick
- ($a, $b....) = unpack("A2A7...", $packed)
- push( array, list )
Followers
Blog Archive
-
▼
2011
(80)
-
▼
October
(19)
- Perl mkdir, make_path and mkpath
- Perl and large integers
- readdir
- Combo box dropdown failure
- CreateProcess
- Pointers to member functions
- Perl system and synchronicity
- AAD and AAM
- Endianness
- Astronomy sky diagrams and photos often have a lit...
- Giving up smoking
- Constructors, temporary objects and initialisation
- new and constructors
- Choice of language
- argv and argc
- C++ static member functions
- do while is not a loop
- C++ structs
- mingw maximum file name length
-
▼
October
(19)