in reply to Rebinding closures

I still don't understand the deal with the grepping. Why not just use a hash?

sub rebind_closure { my $sub = shift; # Let Perl do the odd-numbered hash error handling for you! my %replacement_pairs = @_; my @rules = keys %replacement_pairs; my @replacements = values %replacement_pairs; # ... }

Replies are listed 'Best First'.
Re: Re: Rebinding closures
by diotalevi (Canon) on Dec 18, 2003 at 04:00 UTC
    Hash keys may only be strings while I wanted my keys to be compiled regex objects and code references. You've just coerced every rule into being strings even where it doesn't make sense.
      I guess you're right; I guess I didn't read carefully enough, and then only saw strings being used in your code. On the other hand, it really doesn't make sense to me to allow any replacements besides strings.

        Really? My original thought was to allow stuff like this.

        rebind_closure( $foo, qr/^\$Foo_.+?Bar/ => 23, sub { $_[0] eq '$bar' or $_[0] eq 'foo } => 42 );