in reply to Re: Dynamic given statement
in thread Dynamic given statement

So something like:

my $cases = get_file('cases'); eval qq@ given ('somevar') { $cases } @;

Ewww ugly!! Given how dog-awful slow eval is, I've done my utmost to completely remove it from my lexicon! I think there is only one place in my new system where it appears and then its only invoked if for some reason I have to embed raw Perl into my documents. (I believe that that can be completely avoided tbh)

Replies are listed 'Best First'.
Re^3: Dynamic given statement
by mrstlee (Beadle) on Oct 22, 2011 at 15:49 UTC

    Not sure I follow you altogether but it seems what you want to do is something like:

    while(my $thing = input()){ my $consequence = given_thing($thing,\&get_file,qw(foo bar baz)); ## accept the consequences of your actions ... } sub given_thing { my ($thing,$action,@keys) = @_; do { $thing ~~ $_ and return $action->($thing)} for @keys; }

    I wouldn't be too quick to throw eval away. Sure it is slow and a security risk but the ability to dynamically create executable perl can significantly shorten the road from here to there.

      I concur that eval has it's place, it's just that in most cases there exists a neat solution that can and really ought to be used instead.