Jim Hill wrote:

> $Bill Luebkert in <[EMAIL PROTECTED]>:
> 
>>Jim Hill wrote:
>>
>>
>>>Flags=1414
>>>
>>>Is there a module or a perl algorithm for determining which of
>>>the 14 checkboxes are enabled from a "Flags=" value?
>>
>>I would just use a hash and for loop.  eg: 
> 
> 
> I suspected that there might be solution completely outside my
> ken. Thanks $Bill, another brilliant response.
> 
> 
>>use strict;
>>my $flags = 2;
>>my %hash = (1 => 'Subscriber is Suspended', 2 => 'Receives List Messages', ...);
>>foreach (sort keys %hash) {
>>      print "$hash{$_}\n" if $flags & $_;
>>}
> 
> 
> I don't follow that. How are the keys in the hash processed such
> that they sum to the $flags value?

The keys don't necessarily sum to the $flags value.  Some of the keys may be
present in the $flags value.  The ones that are are printed out - determined
by the bit-wise and.

> Is it possible to get the matching hash values to print out in
> the same order in which the hash was initialised?

Only if the hash sorts to the same order.  You could create an array to
re-order the values for you - where $array[0] has the value to lookup up
in the hash for the first value, etc.  Then the stmt becomes :

my @array = (2, 32, 16, 8, 1, 4);
for (my $ii = 0; $ii < @array; $ii++) {
        print "array ordered: $hash{$array[$ii]}\n" if $flags & $array[$ii];
}


-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to