in reply to Re^2: One liner to Check and undef hash elements (shortcircuiting)
in thread One liner to Check and undef hash elements

Well, the non-sub way could look like this:
my $hash_has_non_undef = do { my $found; until($found or not (undef, m +y $v) = each %hash) { $found = defined $v } $found };
I mean, that's the way we had to do it in Pascal. Stupid boolean flag variables all over the place because they wouldn't let us exit blocks. {grin}

Doh! As I'm staring at this, I realize the $v can do double duty.

my $hash_has_non_undef = do { my $v; until($v or not (undef, $v) = eac +h %hash) { $v = defined $v } $v };
But that's optimized for Golf, not for maintenance. Ick.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^4: One liner to Check and undef hash elements (shortcircuiting)
by Aristotle (Chancellor) on Apr 16, 2003 at 11:53 UTC
    Yeah, I know.. you can at least drop a last in there and simplify the loop condition, if you use a while. Or how about a variant on until:
    my $hash_has_undef = do { local $_; 1 until defined or not (undef, $_) = each %hash; defined; };
    Traded the flag variable for a double defined test on the last value fetched from the hash.

    Makeshifts last the longest.