Thread Regex $1 rechts als Multiplikator für x verwenden (1 answers)
Opened by bianca at 2016-05-26 08:38

bianca
 2016-05-26 08:38
#184829 #184829
User since
2009-09-13
6977 Artikel
BenutzerIn

user image
Guten Morgen!

Bei der Umwandlung einer sprintf() Maske in einen glob() Parameter möchte ich das $1 von links gern rechts als Multiplikator für den x Operator verwenden.

Folgender Test wirf Syntax error. Was mache ich falsch?
Code (perl): (dl )
1
2
3
4
my $test = '/pfad/test_%04d.txt';
$test =~ s/%(\d+)d/(\[0123456789\] x $1)/ge;
say "Debug   : '$test'";
say "Erwartet: '/pfad/test_[0123456789][0123456789][0123456789][0123456789].txt'";

Quote
"my" variable $test masks earlier declaration in same scope at test.pl line 23.
Backslash found where operator expected at test.pl line 24, near "0123456789\"
(Missing operator before \?)
Illegal octal digit '8' at test.pl line 24, within string
Illegal octal digit '9' at test.pl line 24, within string
syntax error at test.pl line 24, near "0123456789\"
BEGIN not safe after errors--compilation aborted at test.pl line 31.

Was der Regex erledigen soll, ist im Prinzip das hier:
my $test2 = '/pfad/test_'.('[0123456789]' x 4).'.txt'

Wenn es dafür ein CPAN Modul gibt nehm ich das gern.
10 print "Hallo"
20 goto 10

View full thread Regex $1 rechts als Multiplikator für x verwenden