I learned this here at PerlMonks: you can execute an expression inside a string or a regex pattern by wrapping it in @{[]}, like so:
#!/usr/bin/env perl use Modern::Perl; my $str = 'abc123efghijk'; my $i = 2; if( $str =~ /(\d{@{[$i+1]}})/ ){ say $1; } # output -> 123
Aaron B.
Available for small or large Perl jobs; see my home node.
In reply to Re: Calculating variable {n} in regex match
by aaron_baugher
in thread Calculating variable {n} in regex match
by atreyu
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |