W
Wim
Hello,
I am trying to make a substition using rules taken from an array. The
basics of the program are:
my @A= ( 'AName-9.45', 'Another-6.123' ) ;
my @NameMap= (
[ qr/^aname-(\d+)\.(\d+)$/io, 'groupzero-$1-$2' ],
[ qr/^another-(\d+)\.(\d+)$/io, q/groupone-$1-$2/ ] ) ;
foreach my $a ( @A ) {
printf "%-17s -> ", $a ;
$a=~ s/$$_[0]/$$_[1]/i foreach ( @NameMap ) ;
printf "$a\n" ;
}
Matching an input string (taken from @A) succeeds. However, replacing
$1 and $2 by the numbers matched between the parenthesis in de left
part fails. the literal string $1 appears in the result. Using
evaluation doesn't work: it will report an uninitialised value. How
can one take both substitute parameters from an array and use local
variables $1 at the same time?
Regards,
Wim Nelis.
I am trying to make a substition using rules taken from an array. The
basics of the program are:
my @A= ( 'AName-9.45', 'Another-6.123' ) ;
my @NameMap= (
[ qr/^aname-(\d+)\.(\d+)$/io, 'groupzero-$1-$2' ],
[ qr/^another-(\d+)\.(\d+)$/io, q/groupone-$1-$2/ ] ) ;
foreach my $a ( @A ) {
printf "%-17s -> ", $a ;
$a=~ s/$$_[0]/$$_[1]/i foreach ( @NameMap ) ;
printf "$a\n" ;
}
Matching an input string (taken from @A) succeeds. However, replacing
$1 and $2 by the numbers matched between the parenthesis in de left
part fails. the literal string $1 appears in the result. Using
evaluation doesn't work: it will report an uninitialised value. How
can one take both substitute parameters from an array and use local
variables $1 at the same time?
Regards,
Wim Nelis.