Re: switch/case (was Re: Want, wrapper subs and context preservation)

[email protected] (Jonathan Scott Duff) Mon, 7 Aug 2000 02:36:48 -0500
Newsgroups perl.perl6.language.subs
Message-ID <[email protected]>
On Mon, Aug 07, 2000 at 05:18:07PM +1000, Damian Conway wrote:
>    > If so, why use a new word rather than hijacking
>    > "if" to do the right thing inside of a switch block?  Perl is already
>    > super context-sensitive anyway.
> 
> You've just convinced me to take else's out of the proposal! ;-)

Glad to be of service!  (But I was hoping you'd get rid of case too ;-)

	switch ([want]) {
	    'LIST'	{ @ret = &wrapped }
	    'SCALAR'	{ $ret = &wrapped }
	    &wrapped
	}

	switch ($num) {
	    0            { return 'zero' }
	    [2,4,6,8]    { return 'even' }
	    [1,3,4,7,9]  { return 'odd' }
	    /[A-F]/i     { return 'hex' }
	}

etc.

-Scott
-- 
Jonathan Scott Duff
[email protected]