Ok, first off your solution doesnt work if $hash{foo}{O} is undef and $hash{foo}{C} does not exist (see the key 'ii' in my test code). Also I didn't notice the existance test on my first try so I did one that ignores that aspect and one that doesnt. So without looking at other offerings heres my test:
use warnings; use strict; my $foo = { aa => { O => 'zz', C => 'yy' }, # bb => { O => 'xx', C => 'xx' }, cc => { O => undef, C => 'ww' }, # dd => { O => 'vv', C => undef }, # ee => { O => undef, C => undef }, ff => { C => undef }, gg => { O => 0, C => 0 }, hh => { O => undef, C => 0 }, # ii => { O => undef }, # }; #Only does defined not exists #98 sub d {$a=pop;grep{$b=$$a{$_};defined$$b{O}!=defined$$b{C}||defined$$b +{O}&&$$b{O}ne$$b{C}}keys%$a} #Does defined and exists #126 sub f {$a=pop;grep{$b=$$a{$_};exists$$b{O}!=exists$$b{C}||defined$$b{O +}!=defined$$b{C}||defined$$b{O}&&$$b{O}ne$$b{C}}keys%$a} # [tadman]s original solution compressed #162 sub t {my($h)=@_;grep{!exists($h->{$_}->{O})||(defined($h->{$_}->{O})? +(defined($h->{$_}->{C})?($h->{$_}->{O} ne $h->{$_}->{C}):1):defined($ +h->{$_}->{C}))}keys%$h} print "d():\n",join("\n",sort {$a cmp $b}d($foo)),"\n\n"; print "f():\n",join("\n",sort {$a cmp $b}f($foo)),"\n\n"; print "t():\n",join("\n",sort {$a cmp $b}t($foo)),"\n\n"; __END__ d(): aa cc dd hh f(): aa cc dd ff hh ii t(): aa cc dd ff hh
So my best was 126 Now to see the others....

--- demerphq
my friends call me, usually because I'm late....


In reply to Re: (Golf) Warningless Comparison by demerphq
in thread (Golf) Warningless Comparison by tadman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.