[Pdx-pm] OT given/when in Perl5

Eric Wilhelm scratchcomputing at gmail.com
Sat May 20 10:13:33 PDT 2006


# 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'."

http://search.cpan.org/~autrijus/Perl6-Bible-0.30/lib/Perl6/Bible/S04.pod#Switch_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
-- 
But you can never get 3n from n, ever, and if you think you can, please
email me the stock ticker of your company so I can short it.
--Joel Spolsky
---------------------------------------------------
    http://scratchcomputing.com
---------------------------------------------------


More information about the Pdx-pm-list mailing list