[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] map, grep in the debugger



Was asked these today...

 

From the Perl debugger, how can I see only those hash keys and contain 'DAY'?

 

$ perl -d -e 1

DB<2> %hash = ( FOO => 1, DAYLIGHT => 2, DAYTIME => 3, BAR => 4)

DB<3> x grep { /DAY/ } keys %hash

   0  'DAYTIME'

   1  'DAYLIGHT'

    

 

What if I want the keys and values where the keys contain 'DAY'?

 

DB<4> x map { $_ => $hash{$_} } grep { /DAY/ } keys %hash

   0  'DAYTIME'

   1  3

   2  'DAYLIGHT'

   3  2

 

 

Perl++   :)

 

j