Logicus has asked for the wisdom of the Perl Monks concerning the following question:
Is there anyway to refactor this so that it does not need the no strict 'refs', and can work under Modern::Perl without it?
use Modern::Perl;$_=' <use><qd>action</></> <use><qd>action</></> '; $_{'s'} = { jeopardy =>"21"}; $_{'qd'} = { action => 'default' }; sub dbl { say "this should only calc once"; $_{'dbl'}->{$_[0]} = $_[0]*2; } sub use { $_{'use'}->{$_[0]} = &simulate_opening_file; } sub simulate_opening_file { say "this should only slurp once"; "The answer is <dbl><s>jeopardy</></>" }; while (/<([^<]+?)>([^<]*?)<\/>/) { my $l=$+[0]-$-[0]; no strict 'refs'; my $r = $_{$1}->{$2} ||= $1->($2); substr($_,$-[0],$l,$r); } say;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: No strict refs
by ikegami (Patriarch) on Aug 21, 2011 at 04:13 UTC | |
|
Re: No strict refs
by Anonymous Monk on Aug 21, 2011 at 03:22 UTC | |
|
Re: No strict refs
by JavaFan (Canon) on Aug 21, 2011 at 23:57 UTC |