Errin == Errin M HMMA/IT Larsen [EMAIL PROTECTED] writes:
Errin And furthermore, I will assume that the values in the hash are boolean
Errin (i.e. '1' (ones) or '0' (zeros)). Now, I want to see if the WHOLE hash
Errin is true, this being defined as every key having a value of '1'.
A bit of
Hi everyone,
As always, we'll start with some necessary code:
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
Let's say I have a hash, but I don't know at compile time how many
keys it has in it:
my %things;
die You have an odd number of
You can use grep.
my %hash = (ONE = 1, TWO = 0, THREE = 1);
if (grep {! $hash{$_}} keys %hash) {
print false\n;
}
else {
print true\n;
}
Prints 'false'.
Chris
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/
You can use grep.
my %hash = (ONE = 1, TWO = 0, THREE = 1);
if (grep {! $hash{$_}} keys %hash) {
print false\n;
}
else {
print true\n;
}
Prints 'false'.
Guess it would be helpful to explain how grep works here. From the perlfunc
man page:
Evaluates the BLOCK or EXPR for each element of LIST
-Original Message-
From: Chris Charley [mailto:[EMAIL PROTECTED]
Sent: Friday, February 04, 2005 10:21 AM
To: beginners@perl.org
Subject: Re: Variable-sized hash of booleans
You can use grep.
my %hash = (ONE = 1, TWO = 0, THREE = 1);
if (grep {! $hash{$_}} keys %hash
-Original Message-
From: Chris Charley [mailto:[EMAIL PROTECTED]
Sent: Friday, February 04, 2005 10:45 AM
To: beginners@perl.org
Subject: Re: Variable-sized hash of booleans
You can use grep.
my %hash = (ONE = 1, TWO = 0, THREE = 1);
if (grep {! $hash{$_}} keys %hash
Larsen, Errin M HMMA/IT wrote:
Hi everyone,
As always, we'll start with some necessary code:
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
Let's say I have a hash, but I don't know at compile time how many
keys it has in it:
my %things;
die You have