Description: A quick and easy way to toggle between two values
(This is based on a friend's code, which was based on merlyn's code in a Web Techniques magazine article in January 1999.)
# In the configuration section...
my @Toggles = ('on', 'off');

# In some loop in the code...
$Toggles[$flip = !$flip]
I use this all the time, usually for background colors:
my @BGColors = ('#dddddd', '#ffffff');

for (1..10){ # As you loop through a database query result or somethin
  print qq{
    <tr bgcolor="$BGColors[$flip = !$flip]">

An easily configured, pretty-to-behold alternating background color.


# To cycle through any number of elements...
my @Cheers = ('hip', 'hip', 'hoo', 'ray');
my $flip = -1;
for (1..12){
  print "$Cheers[$flip = ++$flip % 4]\n";