[tpm] Dealing with nested map { grep {} }

Uri Guttman uri at stemsystems.com
Tue Sep 26 12:46:36 PDT 2017

On 09/26/2017 03:34 PM, Tom Legrady wrote:
> I agree about avoiding overuse of $a & $b, but I see this interior of 
> a map{} as an extension of the situations where there are normally 
> used. There won't be a sort within the map and the map will never be 
> inside a sort.

regardless of the location of a $a, it should never be used outside sort 
because it is special cased not to be checked for strict.

the way to do nested map/grep is to assign $_ lexically to a scalar (not 
named $a). but depending on the data structures you can sometimes to 
sequential map/grep and not nested. i haven't delved into your data yet 
so i can't say.

another trick i use sometimes is when one array can be destroyed so you 
can use shift on it. something like:

my %hash = map { shift @keys => $_ } @vals ;

that may need parens around @keys to allow clean parsing. :/


More information about the toronto-pm mailing list