in reply to Odd and even table rows
The first method I ever used for this was an alternating hash.
or using a slightly obfuscated definition. It even saves 2 characters! :)my ($class, %flip_class) = qw(odd odd even even odd); while (...) { $class = $flip_class{$class}; ... }
Another way I just thought of would be to use grep.my ($class, %flip_class) = qw(odd even)[0,1,0,0,1]; while (...) { $class = $flip_class{$class}; ... }
my $class = 'odd'; while (...) { ($class) = grep {!/$class/} qw(odd even); ... }
Personally, I'd probably stick with a bitwise xor ^, but any of these monastery solutions would work just fine.
- Miller
|
|---|