Randomized Backdrops

#!/usr/bin/perl -w

# This little program sets my background image
# randomly in blackbox (and now openbox).
# It's called when I startx.

$backdrop_directory = "/home/willyyam/crap/backdrop/";
# Set this to your backdrop files directory.

opendir(BD, "$backdrop_directory") or die;
# Normally we'd report errors, but since we will be
# running this via script and discarding the STDOUT
# that it generates, that would be a waste of time.

@backdrops = readdir(BD);
# Grab the contents of the backdrop directory.

@spordkcab = reverse(@backdrops);
# The first two entries readdir() finds are
# . and  ..  We don't want to hand these
# entries to bsetbg, so I reverse the array
# and do away with them.  There is a smooth,
# tidy way to do this.  I don't care :-)

$pic_o_the_moment = $spordkcab[ rand @spordkcab];
$pic_o_the_moment = $backdrop_directory . $pic_o_the_moment;
`/home/willyyam/bin/bsetbg $pic_o_the_moment &`;

# This the program call to bbsetbg, written by
# tmk@lordzork.com, is what does all the work --
# I just call it.


# William O'Higgins yam@nerd.cx


#!/usr/bin/perl -w

# This little program takes a directory as its argument and
# builds an html frame page with all of the image names in one
# frame and a target frame for image viewing.  It leaves the
# three html pages in the argument directory.

print "Enter the directory with the images -- n
make sure it is an absolute path (include a trailing slash):n";
$target_dir = <STDIN>;
chomp $target_dir;

@jpgs = glob("$target_dir*.jpg");
@gifs = glob("$target_dir*.gif");
@both = (@jpgs,@gifs);
@pics = sort(@both);

foreach $pic_name (@pics) {
    $pic_name =~ s/^$target_dir//;

open(MAIN, ">$target_dir"."index.html") or die "Can\'t create index.html: $!n";
open(LEFT, ">$target_dir"."left.html") or die "Can\'t create left.html: $!n";
open(RIGHT, ">$target_dir"."rght.html") or die "Can\'t create rght.html: $!n";

$index_html = "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN""DTD/xhtml1-frameset.dtd">n<html xmlns="http://www.w3.org/1999/xhtml">n<head>n<title>Image Index</title>n</head>n<frameset cols="20%,80%" frameborder="1" border="1">n<frame src="left.html" name="left">n<frame src="rght.html" name="right">n</frameset>n</html>n";

$right_html = "<!DOCTYPE html public "-//W3C//dtD XHTML 1.0 Transitional//EN""DTD/xhtml1-transitional.dtd">n<html xmlns="http://www.w3.org/1999/xhtml">n<head>n<title>Right</title>n</head>n<body></body>n</html>n";

$left_top = "<!DOCTYPE html public "-//W3C//dtD XHTML 1.0 Transitional//EN""DTD/xhtml1-transitional.dtd">n<html xmlns="http://www.w3.org/1999/xhtml">n<head>n<title>Left</title>n</head>n<body>n<dl>nn";

foreach $pic_name (@pics) {
    $pic_name = "<dt><a href = "$pic_name" target = "right">" . $pic_name . "</a></dt>n";

$list = "@pics";

$left_bottom = "nn</dl>n</head>n<body>n";

$left_html = $left_top . $list . $left_bottom;

print MAIN $index_html;
print RIGHT $right_html;
print LEFT $left_html;

close(MAIN) or die "Can\'t close index.html: $!n";
close(LEFT) or die "Can\'t close left.html: $!n";
close(RIGHT) or die "Can\'t close rght.html: $!n";

Search and Replace with Perl

# Sometimes you need to change something in a bunch of files at once.
# These are some command-line ways of doing that.

# For universal replacement (in all files down from the current directory):
find ./ -type f -exec perl -pi -e \'s/stringtofind/stringtoreplacewith/g\' {} ;

# To do all ".php"s, for example:
find ./ -type f -name *.php -exec perl -pi -e \'s/stringtofind/stringtoreplacewith/g\' {} ;

# To find/replace in just the present directory:
perl -pi -e \'s/stringtofind/stringtoreplacewith/g\