> There is no CASE statement in PERL. Instead you use something called
SWITCH.

There is no switch either - and if there was it would be lower case. There
are many ways to emulate it; here is but one:

:HOMOSTART    # this is just a label - it can be ignored
$_ =  $caseVar;

  /^man$/        and do
                          {     sit( ) ;
                                 drink_beer( )
                           };

  /^woman?/    and do
                          {       feed( ) ;
                                   remove beer_cans( )
                           };

  /^child$/       and do
                          {       unitdy_room( );
                                   whine( );
                           };
:HOMEND   # another useless label to prettify the case statement

As an explanation. perl unlike most languages accepts just about anything as
a statement. So for example

'Hello';
'World';

Are two statements. They do not do anything constructive except for certain
special cases. For example:

sub MySub  { 'Hello' }

This subroutine returns the string 'hello'. The following is also a
statement:

/paul/ ;

This searches the 'internal default variable' $_ for the string paul and
returns true or false.

/paul/ and die 'the string should not contain paul';

Checks is $_ contains paul. If it does it 'executes' the second part of the
and and dies.

/^child$/ and do { any_old_code };

Checks if $_ is equal to 'child' (and not just contains it) and if so
executes the following block of code. This should be enouigh to understand
how the case simulation above works.

Paul Cotter
www.powermagic.net




/

Reply via email to