From: oryann9 <[EMAIL PROTECTED]>
> To share some information in the up-incoming Perl 5.10
> there will be a replacement for the switch clause.
>
> The given-when is the Perl answer to the switch
> (or case) keyword in other programming languages.
> It replaces Switch.pm, which was a pre-Perl 5.10
> source filter that did the same thing but didn't
> always
> work correctly.
>
> #!/usr/bin/perl
> use feature qw(say switch);
> chomp( my $var = <STDIN> );
> given( $var ) {
> when( /\D/ ){
> say "Needs a number!"}
> when( $_ == 1 ) {
> say "Got 1!"
> }
> when( $_ == 2 ) {
> say "Got 2!"
> }
> default {
> say "You said $_"
> }
> } ## END given
Which is the same as
sub say {print @_, "\n"}
chomp( my $var = <STDIN> );
for( $var ) {
if( /\D/ ){
say "Needs a number!"
}
elsif( $_ == 1 ) {
say "Got 1!"
}
elsif( $_ == 2 ) {
say "Got 2!"
}
else {
say "You said $_"
}
}
I don't think it's a feature worth making the scripts/modules
unusable in older perls.
Unless the when does have some more magic.
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/