Re: How can you embed a function inside a replacement operator ?



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$
.



Relevant Pages

  • How can you embed a function inside a replacement operator ?
    ... Sorry if this is a basic question. ... How can you embed a function inside a replacement operator? ... sub conv() ...
    (comp.lang.perl.misc)
  • Variables defined in the partial class - ASP.NET 2.0
    ... I apologise in advance for such a basic question, ... Sub btnExcelList_Click(ByVal sender As Object, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Return db record from a function - how?
    ... of a String? ... >> This may be a very basic question but it's something I've never done ... But I want to call a Function from another Sub and the function ... DataReader? ...
    (microsoft.public.dotnet.framework.aspnet)
  • Help with Inheritance
    ... This may be a basic question, but it sure has me stumpted.. ... class has some varibles that need to be reset from time to time, ... dim mPrice as double ... end sub ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Variables defined in the partial class - ASP.NET 2.0
    ... way of handling variable postbacks. ... > Sub btnSet_Click ... >>> I apologise in advance for such a basic question, ... >>> Dim dsExcel As New DataSet ...
    (microsoft.public.dotnet.framework.aspnet)