For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > February 2005 > Case-operator









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Case-operator
Vladimir D Belousov

2005-02-28, 3:56 pm

Hallo!

Is in the perl operator like C/C++ 'case' ?

--
Vladimir D Belousov
HiTech solutions for business
http://businessreklama.ru

Ricardo SIGNES

2005-02-28, 3:56 pm

* Vladimir D Belousov <maillist@klarnet.ru> [2005-02-28T07:01:02]
> Is in the perl operator like C/C++ 'case' ?


I believe you are asking: Is there Perl equivalent to C's switch/case
construct?

Not exactly.

To see the official Perl documentation on this, run: perldoc -q case

This will search the FAQs for the keyword "case" and in the second
question you'll get some information, and a pointer to another bit of
Perl documentation, the "perlsyn" page.

A common idiom is something like this:

SWITCH: for ($value) {
/regex/ and do { something($x); last SWITCH };
/regex/ and do { something($y); last SWITCH };
(! $value) and do { something(0); last SWITCH };

something($default);
}

The documentation mentions Switch, the module. While Switch is neat, I
wouldn't suggest using it in production.

--
rjbs

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com