in reply to Re^4: Doing "it" only once
in thread Doing "it" only once

my %things = (foo => sub {print "skipping foo\n"; next}, bar => sub {handle_bar($_); next}, ); for (@some_array) { (delete $things{$_})->() if exists $things{$_}; handle_rest($_); }

Replies are listed 'Best First'.
Re^6: Doing "it" only once
by Limbic~Region (Chancellor) on Sep 22, 2005 at 12:23 UTC
    Anonymous Monk,
    But that doesn't quite fit the bill. That is the equivalent of keeping it as if statements. Since the value is known to only exist one time the body will only ever be ran once but you still check for it every single time. The difference here is instead of checking the fetching a value and comparing it you are checking for the existance of a key. The point is to make the check and the attached block of code completely go away.

    Cheers - L~R