I am developing a tool currently in Perl, and I need to extract characters from a variable that I put in a regexp. I illustrate directly, it will be clearer.
Code:
my $req = 'select machine from device where machine = $1';
my $separator = "\$";
my $variable = "foo";
$1 is not a variable, but the separator followed by the numeral "1". The separator is intended to be replaced by the variable thereafter that it contains in a string. I put "foo" for example. I then have the following regexp:
Code:
$req =~ s/\Q$sep/$var/;
print "reqfinal = $req\n"; # select code from client where code = foo1
This makes it possible to replace my separator variable. But what I also do is extract the "1" in a variable that I can use later, and also make sure to have that:
Code:
# select code from client where code = toto
in my result, without the "1" then.
Bookmarks