sub GetGalleryFileAndCaptions { my ($URLpicdir,$PATHpicdir) = @_; return "Error: couldn't build gallery. The following directory does not exist: $PATHpicdir" if not (-d "$PATHpicdir"); my @allfiles = (); my @dirs = (); my @CAPTIONS = (); my @PICS = (); my $PicDisplayReturn = ""; opendir(DIR, "$PATHpicdir") or return "Could not open: $PATHpicdir"; @allfiles = sort( readdir( DIR ) ); closedir(DIR); for my $file (@allfiles) { if (-d "$PATHpicdir$file") { push @dirs, $file unless (($file eq ".") or ($file eq "..")); } else { my ($extension) = $file =~ /\.([^.]+?)$/; $extension = lc($extension); push @PICS, $file if ($extension eq "jpg"); } } my $CaptionFile = $PATHpicdir."bu.txt"; #open DATA, "<$CaptionFile" or return qq|Program Error! Could not open file: $CaptionFile. Debugging information: $!|; #chomp (my @LINES = ); #close DATA; open my $rfh, '<', $CaptionFile or return qq|Program Error! Could not open file: $CaptionFile. Debugging information: $!|; { # perldoc perlvar local $/ = ""; @CAPTIONS = <$rfh>; chomp @CAPTIONS; } close $rfh or return qq|Program Error! Could not close file: $CaptionFile. Debugging information: $!|; # for my $line (@LINES) # { # $line =~ s/\015\012|\012|\015/\n/sg; # } # for my $line (@LINES) # { # my ($caption) = split(/\n\n/,$line); # { # push(@CAPTIONS,$caption); # } # } for my $p (0 .. $#PICS) { $PicDisplayReturn .= "PIC:
\"$CAPTIONS[$c]\"
CAPTION:
$CAPTIONS[$c]
"; } #$PicDisplayReturn =~ s/\015\012|\012|\015//sg; return $PicDisplayReturn; }