in reply to Re^2: Control Structures
in thread Control Structures
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; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Control Structures
by jhourcle (Prior) on May 10, 2005 at 13:48 UTC | |
by Roy Johnson (Monsignor) on May 10, 2005 at 15:15 UTC | |
by jhourcle (Prior) on May 10, 2005 at 15:38 UTC | |
by Roy Johnson (Monsignor) on May 10, 2005 at 16:00 UTC |