Geoff Cox said:
On Sun, 24 Aug 2003 00:05:44 +0100, "Peter Cooper"
Peter et al ...
Now trying this - you will perhaps see better what I am trying to
do...problem with the passing of $1 to the sub getintro - I get an
uninitialized value in pattern match error ...
Cheers
Geoff
open(IN, "a2-left.htm");
open(OUT, ">>out");
open(INN, "total");
if (open(IN, "a2-left.htm")) {
Why are you asking to do something if and only if the filehandle is open?
You opened it 3 lines above.
$line = <IN>;
while ($line ne "") {
better for 2 above lines:
if ($line =~ /^<a href/) {
Right here it becomes apparent that you're trying to parse HTML -- which
means you should heed Peter's advice to check out HTML:
arser.
if ($line =~ /="(.*)\.doc/) {
&getintro($1);
}
}
$line = <IN>;
What's the purpose of the line above?
}
}
sub getintro {
@intro = <INN>;
You don't appear to do anything with the content of @intro, so why read from
for ($n=0;$n<900;$n++) {
if ($into[$n] =~ /$1/) {
... unless, that is, you have a typo in line above and meant $intro
But here $1 contains the result of the first captured expression on the last
matching line ... which may not always be what you want.
print OUT ("$into[$n]\n");
print OUT ("$line[$n-1]\n");
}
}
}
close (IN);
close (OUT);
close (INN);
Note: The subject of your OP was "backreference problem." But at no point
in the discussion have you used any backreferences (e.g., \1 as part of a
pattern match). This leads me to suspect that you just don't understand
Perl regexes very well. I recommend going to a good Perl text (e.g., the
llama) and carefully working through the exercises on regexes.