I think your problem is more fundamental than expansion of $1
- I'm going to hazard a guess that the regex isn't matching - because:
$v=$ENV{ACT_NUM};s/TRIGGER_VALUE" value="\d*"/TRIGGER_VALUE" value="$v"/>//
Is actually broken syntax - you're using /
as your regex separator, but you're also trying to include it in your pattern.
So if you actually run this code you get:
Useless use of numeric gt (>) in void context
So perhaps you need to consider escaping some of your meta characters:
This works:
#!/usr/bin/env perl
use strict;
use warnings;
$ENV{ACT_NUM} = 1;
while ( <DATA> ) {
my $v=$ENV{ACT_NUM};
s/TRIGGER_VALUE\" value=\"\d*\"/TRIGGER_VALUE\" value=\"$v\"/;
print;
}
__DATA__
<ins:Parameter name="TRIGGER_VALUE" value="1"/>
But really - messing around with XML
using regular expressions is an inherently bad idea.
You also might want to double check that that environment actually is being propagated. If you print $v
(or $ENV{ACT_NAME}
) does it actually work?
So how about instead:
#!/usr/bin/env perl
use strict;
use warnings;
use XML::Twig;
my $twig = XML::Twig->new(
twig_handlers => {
'ins:Parameter[@name="TRIGGER_VALUE"]' =>
sub { $_->set_att( 'value', $ENV{ACT_NUM} ) }
}
);
$twig->parse(
do { local $/; <> }
)->print;