
CGI hangs due to dodgy escape character
Hi all,
Just moved web servers - this script used to work fine on the old one.
Basic idea is that given a directory of pictures (and a subdirectory
of thumbnails), it creates the HTML to display them.
What is happening now is that it is{*filter*} part way through the
script. It's not very long, so here goes.
#!/usr/bin/perl -w
#
# photos.cgi v1.1 - Antony Gelberg
# Given a directory, displays photos in HTML.
#
use strict;
use CGI;
use Cwd;
my $q = new CGI;
my $dir = $q->param('dir');
my $file = $q->param('file');;
print $q->header();
# Need to be in root directory.
chdir "/var/www/antgel/html" ||
die "Could not chdir to /var/www/antgel/html\n";
if ($dir eq "") {
die "No directory specified in photos.cgi.";
Quote:
} else {
if ($file eq 'thumb') {
# We want thumbnails.
chdir "$dir/thumbnails" || die "Could not chdir to
$dir/thumbnails\n";
my $dirs = `ls -1`;
my $rowsize = 5;
my $column = 1;
print "<TABLE>\n";
if ($column == 1) {
print "<TR>\n";
}
# Fix border attribute in link to css at some point.
print "<TD><A HREF=\"/$dir/$file\"><IMG
SRC=\"/$dir/thumbnails/$file\" BORDER=0><\A><BR>\n";
if ($column eq $rowsize) {
print "</TR>\n";
$column = 0;
}
++$column;
}
print "</TABLE>\n";
} else {
# We want a specific photo.
print "<IMG SRC=\"/$dir/$file\"><BR>\n";
}
Quote:
}
Firstly, I am sure that there are more efficient ways of doing this.
But I come from a C/Java background, and it's hard to pick up Perl
idioms when you can program in a known way.
Anyway it hangs midway through the last iteration of the loop.
Specifically if I hit stop on the browser and view source, it stops
halfway through the long print statement, just before the </A>.
The only light I can shed on it is the error that I get -
"Unrecognized escape \A passed through". I don't think this is
coincidence, but I have no clue how to fix it. I understand that \A
might be construed as an escape character, but as it is being passed
through, I don't see why it has an effect.
Antony