411 REFERENCE · Wikibooks
Perl Programming/Keywords/given
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Perl getsockopt glob Keywords
The given keyword
given is a highly experimental flow-control keyword that is used in a similar manner like the switch keyword in C.
The given loop is supported from Perl 5.10.1 onwards. This can be used with the use feature "switch" or with the use 5.10.1 command. With the given command, the other experimental keywords break, continue, default, and when are also enabled. From Perl 5.16 onwards, it is also possible to use these keywords with the CORE:: prefix and without using the use statements.
In contrast to the switch statement in C with the case parts, the given switch leaves after each when statement without needing a break keyword. If this is not desirable, the continue has to be used.
Syntax
EXPRESSION when EXPRESSION
given EXPRESSION
Examples
use v5.10.1;
given ($var) {
when (/^abc/) { $abc = 1 }; continue;
when (/^def/) { $def = 1 }
when (/^xyz/) { $xyz = 1 }
default { $nothing = 1 }
}
See also
when
Perl getsockopt glob Keywords