in reply to RFC - inplace upgrade for Tie::SortHash

Interesting use of constant, I kind of like it. I would make a wrapper for tie-ing so that you could provide a sub protoyped to accept an optional block so you can change sort/eval definition system. If no sort is specified it should do a default sort (not even the current "smart" default you have coded).

Update, for how to use coderef en lieu of eval.

sub sortblock { my($self, $sort) = @_; local *hash = %{$self->[HASH]}; sort $self->[SORT] keys %hash; $self->[CHANGED] = 1; }

--
I'm not belgian but I play one on TV.

Replies are listed 'Best First'.
Re: Re: RFC - inplace upgrade for Tie::SortHash
by Limbic~Region (Chancellor) on Aug 10, 2003 at 02:39 UTC
    belg4mit,
    I tried for the better part of an hour trying to figure out how to do one of the following with no luck:
  • Get rid of the eval all together
  • Prefer not to use eval, but allow it for backwards compatability

    The issue is that you are creating a sort routine for a %hash that is defined in the module, not the calling script.
    I don't see how to get around this even with your suggestion and updated code.

    The smart sort came from the original module - I left it for backwards compatability.

    Cheers - L~R

    Update: I figured out how to do the second one. eval is now only used for backwards compatability if the calling script uses the old q($a cmp $b) syntax instead of a code ref: