Brandon Willis > IfLoop > IfLoop

Download:
IfLoop-0.03.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.03   Source  

NAME ^

IfLoop - An extension to the if-elsif-else syntax in Perl.

SYNOPSIS ^

  use IfLoop qw( while until );

DESCRIPTION ^

IfLoop allows for the creation of if-elsif-else chains that contain loop structures in the if-elsif-else syntax. Just like if-elsif-else chains if-elsifwhile-elsifuntil-else chains can be of arbitrary length and can be nested. Any ifwhile, elsifwhile, etc. syntax can be intermingled with the normal if-elsif-else chains to create combination chains. (See EXAMPLES)

EXAMPLES ^

 #Use all extensions
 use IfLoop;


 # Only use the ifwhile/elseifwhile extension.
 use IfLoop qw( while );

 ifwhile(A)
 {
     #code...
 }
 else
 {
     #code...
 }

 # Use both the ifuntil/elseifuntil and ifwhile/elsifwhile extensions.
 use IfLoop qw( until while );

 if(A)
 {
     #code...
 }
 elsifuntil(B)
 {
     #code...
 }
 elsifwhile(C)
 {
     #code...
 }
 else
 {
     #code...
 }

LITERAL TRANSLATION ^

IfLoop actaully just translates its extended syntax into normal Perl syntax. Here are the translations.

 ifwhile(A)
 {
     #code...
 }

translates to:

 if(A)
 {
     do
     {
        #code
     }while(A)
 }

 ifuntil(A)
 {
     #code...
 }

translates to:

 if(!(A))
 {
     do
     {
        #code
     }until(A)
 }

Translation of elsif statments occur in the same way.

TODO ^

Add the for and foreach syntax.

BUGS/QUIRKS ^

The syntax code ifwhile(A); does not work. (No explicit warning from module, but Perl complains of a bareword on the offending line.)
When using <>'s to set $_ in a loop it must be done explicitly. (IfLoop will die with a warning that suggests the proper usage.)

AUTHOR ^

Brandon Willis, brandon@silverorb.net

THANKS ^

IfLoop's implementation was heavily inspired by Damian Conway's Switch.pm.

COPYRIGHT AND LICENCE ^

 Copyright (c) 2003, Brandon Willis. All Rights Reserved.
 This module is free software. It may be used, redistributed
 and/or modified under the same terms as Perl itself.

SEE ALSO ^

perl.

HISTORY ^

0.02

Initial Release

0.03

doc/code clean-up Fixed comment bug.

syntax highlighting: