perl_hint_immediate_subscripting_anonymous_array_to_handle_date_

This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.



From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Switch statement in Perl
Date: Fri, 07 Jul 2000 19:46:17 GMT

Abel Almazan wrote:

> want to translate this:
>
>if ($wday==1) $day="Monday";
>elsif ($wday==2) $day="Thursday";
>.
>.
>.
>else $day="Sunday";
>
>to switch statement

Oh damn. What about:

	$day = (qw(Sunday Monday Tuesday Wednesday Thursday Friday
	  Saturday Sunday))[$wday];

And no, it's no mistake that "Sunday" is in there twice. It't there for
both indexes 0 and 7.

It's far more compact and elegant (and probably even faster) than any
switch statement you could possibly get. Or: you're wrong. You don't
want a switch statement.

-- 
	Bart.


the rest of The Pile (a partial mailing list archive)

doom@kzsu.stanford.edu