sub case_new { my $matched = 0; return sub { my $check = shift; return $matched if $matched; if (ref $check eq 'Regexp') { return $matched = /$check/; } else { return $matched = $_ eq $check; } } } sub clean_up_values {print "Clean up values\n"} sub do_whatever_you_need_to {print "Whatever you need\n"} sub do_something_else {print "Something else\n"} sub do_some_default_thing {print "Default\n"} for my $value ('testing', 'needs_slight_cleaning', 'good value', 'tota +lly unrelated') { print "Checking $value..."; my $case = case_new; for ($value) { $case->('needs_slight_cleaning') && &clean_up_values; $case->('good value') && do { &do_whatever_you_need_to; last; }; $case->('totally unrelated') && do { &do_something_else; last; }; default: &do_some_default_thing; } }
In reply to Re^3: Control Structures
by Roy Johnson
in thread Control Structures
by artist
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |