Re: How can you embed a function inside a replacement operator ?
- From: nolo contendere <simon.chao@xxxxxxx>
- Date: Tue, 27 Nov 2007 07:13:47 -0800 (PST)
On Nov 27, 10:08 am, neilsolent <n...@xxxxxxxxxxxxxxxxxxxxxx> wrote:
Hi
Sorry if this is a basic question.
How can you embed a function inside a replacement operator ?
e.g.:
####################################
sub conv()
{
return $_[0] * 2;
}
$test = 'abc125abc';
$test =~ s/(\d+)/&conv($1)/g;
print $test . '\n';
####################################
The output of this script is:
abc&conv(123)abc
Whereas I would like it to be:
abc250abc
my $test = 'abc125def';
$test =~ s/(\d+)/conv($1)/ge;
print $test, "\n";
sub conv {
my ( $val ) = @_;
return $val * 2;
}
__OUTPUT__
bash-2.03$ ./replace_func.pl
abc250def
bash-2.03$
.
- References:
- How can you embed a function inside a replacement operator ?
- From: neilsolent
- How can you embed a function inside a replacement operator ?
- Prev by Date: Re: How can you embed a function inside a replacement operator ?
- Next by Date: Re: Perl usage
- Previous by thread: Re: How can you embed a function inside a replacement operator ?
- Index(es):
Relevant Pages
|