Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Version II of this script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Version II of this script
Authored by: d1taylor on Jan 12, '02 03:08:27AM
I have taken Kevin's script and made a bunch of tweaks and changes to have it be a bit more general purpose. I've also added some comments and unwrapped the code to be a bit more readable:
#!/usr/bin/perl -w

# Written by KevinL
#  with minor tweaks by Dave Taylor <taylor@intuitive.com>

#
# Note: this is best run by cron every day, so that your images are
# constantly shuffling around. To do that, you'll want to make sure 
# that this program switches to the correct directory, which is most
# easily done by including the following line (with the directory
# specification changed to your own Screen Saver Images directory,
# of course!):

# chdir("/Users/kevin/Pictures/Desktop Pictures") || die "I can't chdir";

srand;          # initialize random number package

foreach $file (<*.[jJ][pP][gG]>) {
  if ($file !~ /^[0-9]+_/ ) {
    $pref=int rand(100); 
    $new=$pref."_".$file; 
    rename ($file, $new);
  }
  elsif ($file =~ /^[0-9]+_/) {
    $pref=int rand(100); 
    $_=$file; 
    s/[0-9]+_/$pref_/; 
    rename ($file, $_);
  }
}
Comments??
Btw, how do you avoid having code listings in a <PRE> double-spaced? I have post mode = HTML Formatted, but it's still adding <br> after each line. Blech.


[ Reply to This | # ]
Version II of this script
Authored by: pmccann on Jan 13, '02 10:08:45AM

Given Kevin's explanation of the problem with backslashing the underscore in the substitution operator I'll assume that you've done that (and had it promptly stripped by the formatter...)

As with all the scripts displayed above, the "elsif" condition is redundant (it's no big deal, but you asked!). Might as well just have

else{
#as per above
}

instead of a condition that's already been satisfied. Oh yeah: I wish I could give advice about formatting, but I'm forever stuffing up html submissions so I'll humbly refrain from doing so!

Cheers,
Paul



[ Reply to This | # ]