in reply to Regexs on Hash Keys

Here's a stab:
%fdat = ( 'redirect_sam' => 'boondoggle' ); $fdat{$_} = $fdat{"redirect_$_"} for map /^redirect_(.*)$/, keys %fdat;

Or, alternately:

for(keys %fdat) { $fdat{$1} = $fdat{$_} if /^redirect_(.*)$/; }

Don't know if you'll gain any speed from it, though. Please note, I used map instead of grep for the first snippet because I just wanted to return the matched part, not the entire list element as grep does.

HTH

'kaboo

Update:
Sigh... too slow... I like merlyn's tho, it's purtee.

Replies are listed 'Best First'.
(tye)Re: Regexs on Hash Keys
by tye (Sage) on Dec 01, 2000 at 03:01 UTC

    I don't think your first one works. Here is a modified version:

    $fdat{$_} = $fdat{"redirect_$_"} for map { /^redirect_(.*)$/ ? $1 : () } keys %fdat;

    Update: I did a lot of work for nothing. In a list context, a matching m// returns the list of captures, ($1), in this case. And a non-matching m// returns the empty list, (), not for example, a list containing one false value. This last item has bitten me several times; you'd think I'd have learned by now. ):

    Thanks to chipmunk for reminding me of this.

            - tye (but my friends call me "Tye")