in reply to Re: grep for hash?
in thread grep for hash?
I was surprised that this not only works, but also does not complain if strictures are added to the code.
The code looks ingenious, but I wonder about two aspects: First, you are accessing a list one time as a hash via %NAME, and then the same list as an array, via @NAME. Is this considered accepted practice? Honestly, I hadn't expected it to work with lexically scoped variables, and I'm not sure whether this trick (if I can call it like this) will remain with later Perl versions.
A more serious problem is the linewhere you rely on the fact that @keys gets its value first (from the grep) before it is used to form a slice for @new. I think this is undefined behaviour, isn't it?@new{ @keys } = @orig{ @keys = grep /[adf]/, keys %orig };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: grep for hash?
by Fletch (Bishop) on Jul 07, 2009 at 15:25 UTC | |
by ikegami (Patriarch) on Jul 07, 2009 at 15:50 UTC | |
by Fletch (Bishop) on Jul 07, 2009 at 16:34 UTC | |
by ikegami (Patriarch) on Jul 07, 2009 at 16:38 UTC | |
by Fletch (Bishop) on Jul 07, 2009 at 16:54 UTC |