S
Sandman
Hello again, and thanks to Anno Siegel for your answer to my earlier thread
(on the subject, but
unfortunately, the conditions for my need has slightly altered, and I want some
further help (from anyone, not just Anno).
Here is a code snippet that probably illustrates what I want to do:
-------------
#!/usr/bin/perl
use strict;
use warnings;
my $string = "Hello World!";
my %array = (
"Hello (.*?)!", "Goodbye, little #1#!"
# search reply
);
foreach (keys %array){
if ($string=~m/$_/i){
# It matched!
$array{$_}=~s/#(\d+)#/$$1/;
# replace #1# with $1, #2# with $2
# from the match above
print "$string\n\n";
print "$array{$_}\n\n";
# Add the reply to the string
}
}
-------------
Wanted output:
Hello World!
Goodbye, little World!
So, as opposed to my earlier thread, I no longer seek to replace the original
string, but rather add a "reply" to it, if it matches. Basically, what I want
to do is replace the string #1#, #2#, #3#... with the values in $1, $2, $3...
but when trying to do that, perl complains about:
File "test.pl"; Line 15: Can't use string ("1") as a SCALAR ref while
"strict refs" in use
Line 15 being:
$array{$_}=~s/#(\d+)#/$$1/;
Thanks for any help.
(on the subject, but
unfortunately, the conditions for my need has slightly altered, and I want some
further help (from anyone, not just Anno).
Here is a code snippet that probably illustrates what I want to do:
-------------
#!/usr/bin/perl
use strict;
use warnings;
my $string = "Hello World!";
my %array = (
"Hello (.*?)!", "Goodbye, little #1#!"
# search reply
);
foreach (keys %array){
if ($string=~m/$_/i){
# It matched!
$array{$_}=~s/#(\d+)#/$$1/;
# replace #1# with $1, #2# with $2
# from the match above
print "$string\n\n";
print "$array{$_}\n\n";
# Add the reply to the string
}
}
-------------
Wanted output:
Hello World!
Goodbye, little World!
So, as opposed to my earlier thread, I no longer seek to replace the original
string, but rather add a "reply" to it, if it matches. Basically, what I want
to do is replace the string #1#, #2#, #3#... with the values in $1, $2, $3...
but when trying to do that, perl complains about:
File "test.pl"; Line 15: Can't use string ("1") as a SCALAR ref while
"strict refs" in use
Line 15 being:
$array{$_}=~s/#(\d+)#/$$1/;
Thanks for any help.