develooper Front page | perl.perl5.porters | Postings from August 2009

Re: RC1 has the old perlfaq

Thread Previous | Thread Next
From:
Steffen Mueller
Date:
August 13, 2009 05:23
Subject:
Re: RC1 has the old perlfaq
Message ID:
4A84059D.8080702@sneakemail.com
Hi brian,

brian d foy wrote:
> http://github.com/briandfoy/perlfaq/tree/master

I'm currently looking at the perlfaq7 entry for "Can I haz switch". It 
has a large piece of code that's supposed to emulate a switch statement. 
I'm not convinced it's useful any more given that there's both a simple 
if-then-else and a give-when example right next to it.

     SWITCH: for (ref $whatchamacallit) {

	/^$/		&& die "not a reference";

	/SCALAR/	&& do {
				print_scalar($$ref);
				last SWITCH;
			};

	/ARRAY/		&& do {
				print_array(@$ref);
				last SWITCH;
			};

	/HASH/		&& do {
				print_hash(%$ref);
				last SWITCH;
			};

	/CODE/		&& do {
				warn "can't print function ref";
				last SWITCH;
			};

	# DEFAULT

	warn "User defined type skipped";

     }

(horrors)

Cheers,
Steffen

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About