in reply to Pass conditions to a subroutine
You could use eval EXPR, but passing a sub reference is safer, clearer and easier.
my $condition = sub { !-d $_[0] }; my $result = checkForDirectory($condition); sub checkForDirectory { my $condition = shift; ... if ($condition->($someDir)) { doSomethingElse(); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Pass conditions to a subroutine
by Fletch (Bishop) on May 13, 2008 at 19:15 UTC | |
|
Re^2: Pass conditions to a subroutine
by PerlRob (Sexton) on May 13, 2008 at 18:08 UTC |