Why is this generating the error:
Use of uninitialized value $match in substitution (s///) at ...
my $sub = 0; #added
my $m; #added
open (FH1, "<FILE1.txt") || die $!;
open (FH2, "<FILE2,txt") || die $!;
my @strings = (<FH2>); #each line of the file into an array
close FH2 or die $!;
my $here;
while ( my $url = <FH1> ) {
chomp $url;
foreach my $sub (@strings) {
my $repeat = 1;
while ((my $m = $_) =~ s|(?<![/])(?:[/](?![/])[^/]*){$repeat}[^/]*\K|$sub|) #<-- Error states the error is occurring here
{
print "$m\n";
$repeat++;
push( @{ $here->{$url} }, $m );
}
}
}
There is definitely something in the files (as I can print each of the lines inside the foreach
loop) and the regular expression substitution definitely works as it has been tested in its own program before I tried to move it into this program.
Is it something obvious I'm overlooking?
Your help would be much appreciated, many thanks