Luke Palmer <[EMAIL PROTECTED]> writes:
> Smylers writes:
>> Perl 5 C<s///g> currently returns the number of substitutions made.
>> This has its uses, so Perl 6 C<s:e///> should probably continue to do
>> this.
>> 
>> Can we have a return value that stringifies to the result of the
>> substitution but numifies to the number of substitutions made and
>> boolifies based on the number rather than the string (to allow for
>> situations such as a successful substitution producing an empty string)?
>> 
>> Would we want that anyway?  It means there's a difference between:
>> 
>>   $substituted = $text ~~ s/$pattern/$replacement/;
>>   if $substituted
>> 
>> and:
>> 
>>   if $text ~~ s/$pattern/$replacement/
>> 
>> which doesn't sound like a great feature to leave lying around in a
>> language.
>
> Probably wouldn't want that.  But returning the text substituted isn't
> necessarily a bad idea, especially if it has a C<but true> on it.
>
> As long as there's a way to strip boolifying properties en passant.
>
>     $substituted = ($text ~~ s/$pattern/$replacement/) but nothing;
>
> Seems rather authoritative, doesn't it? :-)

Oh! I like that. This would, presumably strip off *all* but related
properties. (Say that aloud to your colleagues and watch their
expressions). 

> What I really want is a functional version of s///.  Like:
>
>     my $substituted = $text.s(/$pattern/, { $replacement });
>
> Without modifying $text.

That would be handy too. 

Reply via email to