On Mon, 30 Sep 2002, Michael Fowler wrote:
> I cannot duplicate your problem. Given the code:
>
> perl -wle 'print "hi" if defined $bar && (!defined $foo || abs($foo)
> < 100)'
>
> I see no 'Use of uninitialized value' warnings, and no print. Are you
> certain the code you posted is what you're actually using? Is there
> relevant code prior to what you posted, such as initializations of your
> variables?
The snippet that I included in the message was a reduced version of the
script. I've attached the script to this message. (I hope that this isn't
a breach of etiquete.) Here's the first 20 lines or so...
#!/usr/bin/perl -w
use Text::Template;
use Image::Magick;
use Getopt::Long;
use File::Path;
use FindBin qw($Bin);
use POSIX;
use strict;
use vars qw($comment $directory $max_rows $max_cols $lg_dim $saturation
$normal $last_index $indiv_template $index_template @files @html_files
@old_indexes);
GetOptions(
'comment=s' => \$comment,
'directory=s' => \$directory,
'rows=i' => \$max_rows,
'cols=i' => \$max_cols,
'largedim=i' => \$lg_dim,
'normalize' => \$normal,
'saturation:i' => \$saturation
);
unless (defined $directory && defined $comment && defined $max_rows &&
defined $max_cols && defined $lg_dim && $lg_dim =~ m/[1-9][0-9]?/ &&
(!defined $saturation || abs($saturation) < 100)) {
# print individual error messages
exit;
}
# continue if all req'd variables were defined and the optional variables
# were within tolerances
-- Eric P.
Sunnyvale, CA
#!/usr/bin/perl -w
use Text::Template;
use Image::Magick;
use Getopt::Long;
use File::Path;
use FindBin qw($Bin);
use POSIX;
use strict;
use vars qw($comment $directory $max_rows $max_cols $lg_dim $saturation $normal
$last_index $indiv_template $index_template @files @html_files @old_indexes);
my $copyright = 'Copyright 2002, Fun 4-Wheel Drive Association\nPretorious Networks -
www.Pretorious.net';
GetOptions(
'comment=s' => \$comment,
'directory=s' => \$directory,
'rows=i' => \$max_rows,
'cols=i' => \$max_cols,
'largedim=i' => \$lg_dim,
'normalize' => \$normal,
'saturation:i' => \$saturation
);
unless (defined $directory && defined $comment && defined $max_rows && defined
$max_cols && defined $lg_dim && $lg_dim =~ m/[1-9][0-9]?/ && (!defined $saturation ||
abs($saturation) < 100)) {
print "Specify a directory to scan (e.g., --directory /etc)\n" unless
$directory;
print "Provide a comment for the photos (e.g., --comment foobar)\n" unless
$comment;
print "Specify the number of rows and columns in the indexes (e.g., --cols 5
--rows 5)\n" unless ($max_rows && $max_cols);
print "Specify a number between -99 and 99 for the image saturation value
(e.g., --saturation -50)\n" unless (abs($saturation) < 100);
print "Specify a number between 1 and 99 for the images\' final size as a
percentage of the beginning size (e.g., --largedim 75)\n" unless ($lg_dim > 0 &&
$lg_dim < 100);
exit;
}
unless (-d "$Bin/$directory" or ($directory =~ m|^/| and -d $directory)) {
print "Invalid directory: $directory\nDirectory $directory must exist within
$Bin\n";
exit;
} else {
# Strip any trailing-slashes from $directory
$directory =~ s|/$||;
opendir(DIR, $directory) or die "Could not open $directory: $!\n";
# Create an array of the image files' names
# Create a parallel array of HTML file names
# Create an array of old index-#.html files to remove
for (readdir(DIR)) {
next unless ( -f "$directory/$_");
if ((my $file_base = $_) =~ s/\.(jpg|gif)$/\.html/i) {
push (@files, $_);
push (@html_files, "$file_base.html");
next;
}
push (@old_indexes, "$directory/$_") if (m/html$/);
}
closedir(DIR) or die "Could not close $directory: $!\n";
# Calculate the number of index files to create
$last_index = ceil((scalar @files) / ($max_rows * $max_cols));
rmtree([@old_indexes, "$directory/html", "$directory/sm_images",
"$directory/lg_images"]);
mkpath(["$directory/html", "$directory/sm_images", "$directory/lg_images"]) or
die "Could not create subdirectories within $directory: $!";
$index_template = Text::Template->new(
TYPE => 'FILE',
SOURCE => "$Bin/index_template.tmpl"
);
$indiv_template = Text::Template->new(
TYPE => 'FILE',
SOURCE => "$Bin/indiv_template.tmpl"
);
}
my ($prev_href, $next_href, $prev_html, $next_html, $file_list, $index_hyperlist);
my $curr_index = 1;
for (my $x = 0 ; $files[$x] ; $x++) {
push (@$file_list, $files[$x]);
my ($image, $im) = Image::Magick->new();
$im = $image->Read(filename => "$directory/$files[$x]");
$im .= $image->Resize(geometry => '192x256');
$im .= $image->Modulate(saturation => $saturation) if $saturation;
$im .= $image->Normalize() if $normal;
$im .= $image->Comment($copyright);
$im .= $image->Write(filename => "$directory/lg_images/$files[$x]");
warn "$im" if $im;
undef $image;
# Not the most efficient solution but certainly easy to follow...
if ($x ==0) {
# If this is the first
$prev_href = '';
$next_href = "./$html_files[$x+1]";
} elsif ($x == $#files) {
# Or this is the last
$prev_href = "./$html_files[$x-1]";
$next_href = '';
} else {
$prev_href = "./$html_files[$x-1]";
$next_href = "./$html_files[$x+1]";
}
open(INDIV, "> $directory/html/$html_files[$x]") or die "Could not create
$directory/html/$html_files[$x]: $!\n";
$indiv_template->fill_in(OUTPUT => \*INDIV, HASH => {
title => $comment,
img => "../lg_images/$files[$x]",
prev => $prev_href,
index => "../index-$curr_index.html",
next => $next_href,
ext => 'jpg'
});
close(INDIV) or die "Could not close $directory/html/$html_files[$x]: $!\n";
# If (@$file_list is full || There are no more files to parse)
if (scalar @$file_list == $max_cols * $max_rows || $x == $#files) {
# Not the most efficient solution but certainly easy to follow...
if ($last_index == 1) {
# If there's only going to be 1 index page
$prev_href = '';
$next_href = '';
} elsif ($curr_index == 1) {
# If this is the 1st index page
$prev_href = '';
$next_href = $curr_index + 1;
} elsif ($curr_index == $last_index) {
# If this is the last index page
$prev_href = $curr_index - 1;
$next_href = '';
} else {
$prev_href = $curr_index - 1;
$next_href = $curr_index + 1;
}
for (1..$last_index) {
if ($_ == $curr_index) {
$index_hyperlist .= " $_ ";
} else {
$index_hyperlist .= " <A HREF=./index-$_.html>$_</A>
";
}
}
open(INDEX, "> $directory/index-$curr_index.html") or die "Could not
create $directory/index-$curr_index.html: $!\n";
$index_template->fill_in(OUTPUT => \*INDEX, HASH => {
title => $comment,
list => $file_list,
cols => $max_cols,
prev => $prev_href,
index_list => $index_hyperlist,
next => $next_href,
ext => 'jpg'
});
close(INDEX) or die "Could not close
$directory/index-$curr_index.html";
$curr_index++;
undef $file_list;
undef $index_hyperlist;
}
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]