in reply to Re^2: surprised to find cannot assign s/../../ to a variable
in thread surprised to find cannot assign s/../../ to a variable
> > For storing complex code use a subroutine
> > sub repl { $_[0] =~ s/a/b/ }
Hence...
DB<9> %options = ( r => sub { $_[0] =~ s/(a)/A/gr } ) # r is set DB<10> x @name = $options{r}->('abc') 0 'Abc' DB<11> $options{b} //= sub { $_[0] =~ s/(b)/B/gr } # b defaulted if + undefined DB<12> x @name = $options{b}->('abc') 0 'aBc' DB<13> $options{r} //= sub { $_[0] =~ s/(b)/B/gr } # r exists DB<14> x @name = $options{r}->('abc') 0 'Abc' DB<15>
Your use of a list assignment to @name in combination with /r looks wrong tho
Anyway, welcome in the world of functional programming
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
|
|---|