You've got lots of problems, some critical, some minor.

A quick rundown:

Here's essentially your code with the above mentioned things modified. Note: the way I'm extracting the info for the %figures hash is pretty fragile. There are probably better methods I could have suggested if I'd had better information on the layout of your data files.

Untested

# ARGUMENTS: engine_figurelinks.pl xx_manual_vvv # where xx = manual code, vvv = version # # MODIFICATIONS: # #--------------------------------------------------------------------- +- use strict; use warnings; use diagnostics; #use Env qw(SERVER_NAME); #use CGI qw(:standard :netscape); use File::Copy; # Perl supplied module for making copies #new CGI; #--------------------------------------------------------------------- +- my $manualdir_param = shift @ARGV; my $working_dir = $manualdir_param; $working_dir =~ s/manualdir=//i; my $data_area = "/tmp"; my $html_dir = "$data_area/$working_dir"; my %figures; #--------------------------------------------------------------------- +- # Loop to locate HTML files, change permissions, and make working temp +orary copies opendir my $htmlstories, "$html_dir" or die "HTML dirs do not exist: $ +!\n"; my @FigureArray = grep { /^09\w{1,5}00$/ } readdir($htmlstories); closedir $htmlstories; foreach my $FigFile (@FigureArray) { next unless (-d $FigFile); opendir my $htmstory, "$html_dir/$FigFile" or die "Directory does not exist: $!\n"; my @FileArray = grep { /a\.htm$/ } readdir($htmstory); closedir $htmstory; foreach my $DirFile (@FileArray) { my $filename = "$html_dir/$FigFile/$DirFile"; next unless (-f $filename); copy( $filename, $filename . '.bak' ) or die "Can not make backup copy of file: $1"; chmod 0600, $filename; open my $fh, '<', $filename or die "Could not open file: $!\n" +; my $figure; while ( my $line = <$fh> ) { if ( $line =~ /(<IMG SRC=.*?>)/ ) { $figure = $1; next; } if ( $line =~ /(Figure \d+)/ ) { $figures{$1} = $figure; } } close $fh; } } print "$_ => ",$figures{$_},"\n" for sort keys %figures;

In reply to Re: Regular Expression Pattern Search Problem by thundergnat
in thread Regular Expression Pattern Search Problem by xdbd063

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.