in reply to Re^4: Function call in regex replacement string
in thread Function call in regex replacement string
With that said, your program is the same as:
Yeah, it is a hack. But which hack would you prefer to maintain?#! /usr/bin/perl -ni BEGIN { @ARGV = my $file = "hai"; die "File '$file' doesn't exist!" unless -e $file; } print if s/HAI WORLD Times ([0-9]+).*/ "\t\t<exML LOLZ = \"" . unpack(\'a1\', $1) . "\" />" /eg;
And a random note. Rather than eval you can just use a closure:
This has a number of advantages, including much better performance, and the fact that errors are not accidentally trapped. (Trust me, if you're evaling code from a configuration, you want to know if the configuration is bad.)$replaceString = sub { "\t\t<exML LOLZ = \"" . unpack(\'a1\', $1) . "\" />" }; # time passes $array[$elementIdx++] = $replaceString->();
|
|---|