[Pdx-pm] OT given/when in Perl5

Dave dave at dhdo.org
Sat May 20 12:10:42 PDT 2006


I've found perl uses the word 'for' instead of 'switch':

for( $var ) { 
	/test/ && do { ...; last; };
	another test && do { ...; last; }
	{ default stuff; }
}

Seems like using the scary prototype and fenangling it into a different name 
is a lot of work for not a lot of result..

As to the question if anyone has done it.. probably.  Most people don't 
bother. 

On Saturday 20 May 2006 10:13, Eric Wilhelm wrote:
> # from Austin Schutz
>
> # on Saturday 20 May 2006 03:09 am:
> >>   http://scratchcomputing.com/tmp/given_when.pl
> >>
> >> (This is just a first hack to work out the semantics.)
> >
> >        This has come up in the past on this list.
> >
> >        I've been known to do something like:
> >
> >while(defined($_ = shift(@ARGV))){
> >  /^-file/ && do {
> >    $filename = shift(@ARGV);
> >  };
> >  /^-debug/ && do {
> >   ...
> >  };
> >  ...
> >}
>
> Okay, but think "academic exercise" (and maybe "cheating".)  More "is it
> possible to morph the language?" than "perldoc -q 'switch or case'."
>
> //search.cpan.org/~autrijus/Perl6-Bible-0.30/lib/Perl6/Bible/S04.pod#Shttp:
>witch_statements
>
> Sugar, not meat :-)
>
> I've since learned that perl 5.9 includes it as an optional feature.
>
>   use feature 'switch';
>
> http://search.cpan.org/~rgarcia/perl-5.9.3/lib/feature.pm
>
> But the question remains as to whether anyone has done this in Perl5
> Perl.  I'm not trying to exactly match the Perl6 syntax, just come up
> with a source-filterless approximation.
>
> --Eric

-- 
-Dave


More information about the Pdx-pm-list mailing list