S
Sandman
Ok, so here is a snippet that shows what I want to do:
#!/usr/bin/perl
use strict;
use warnings;
my $string = "Hello World!";
my %array = (
"Hello (.*?)!", "Goodbye, little #1#!"
# search replace
);
foreach (keys %array){
if ($string=~m/$_/i){
# It matched!
$array{$_}=~s/#(\d+)#/$$1/;
# replace #1# with $1, #2# with $2...
$string=~s/$_/$array{$_}/g;
# replace the string;
}
}
print $string;
The wanted result is "Goodbye, little World!", fetching "World" from $1 of the
match 4 lines up, but the error message is
File "test.pl"; Line 14: Can't use string ("1") as a SCALAR ref
while "strict refs" in use
So how do I solve it?
#!/usr/bin/perl
use strict;
use warnings;
my $string = "Hello World!";
my %array = (
"Hello (.*?)!", "Goodbye, little #1#!"
# search replace
);
foreach (keys %array){
if ($string=~m/$_/i){
# It matched!
$array{$_}=~s/#(\d+)#/$$1/;
# replace #1# with $1, #2# with $2...
$string=~s/$_/$array{$_}/g;
# replace the string;
}
}
print $string;
The wanted result is "Goodbye, little World!", fetching "World" from $1 of the
match 4 lines up, but the error message is
File "test.pl"; Line 14: Can't use string ("1") as a SCALAR ref
while "strict refs" in use
So how do I solve it?