in reply to how to loop

How about this?

while ($mode eq 'running') { my $new = $backs[int(rand(@backs))]; system($command . ' --type=string -s '. $gconf_item . ' \'' . $new + . '\''); sleep($interval*60); }
That's not exactly equivalent to your code, but all sorts of adjustments are possible

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: how to loop
by rsiedl (Friar) on Feb 21, 2007 at 02:20 UTC
    thanks. i guess this'll work:
    while (1) { # Get a random background from the array my $new = $backs[int(rand(@backs))]; # Set the background to something new system($command . ' --type=string -s '. $gconf_item . ' \'' . $new . + '\''); last if ($mode ne "running"); sleep($interval*60); } # end-while
      From a maintenance perspective, I like the previous example a bit more because you can understand the exit condition by reading the while line. Even a non-coder could understand it: while ($mode eq 'running'); keep going while the mode equals 'running'.

      In your example, I have to search through the entire block and find the 'last if' line to figure out how you break out of the loop.

      They are basically equal, but I find the first example easier to read and understand.