Re: Variable-sized hash of booleans

2005-02-05 Thread Randal L. Schwartz
> "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'.

Re: Variable-sized hash of booleans

2005-02-04 Thread John W. Krahn
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

RE: Variable-sized hash of booleans

2005-02-04 Thread Larsen, Errin M HMMA/IT
> -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 =>

RE: Variable-sized hash of booleans

2005-02-04 Thread Larsen, Errin M HMMA/IT
> -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,

Re: Variable-sized hash of booleans

2005-02-04 Thread Chris Charley
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

Re: Variable-sized hash of booleans

2005-02-04 Thread Chris Charley
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]