develooper Front page | perl.perl5.porters | Postings from July 2012

Re: [perl #113962] /r modifier on substitutions - variant returningundef if no match

Thread Previous
From:
David Golden
Date:
July 24, 2012 08:51
Subject:
Re: [perl #113962] /r modifier on substitutions - variant returningundef if no match
Message ID:
CAOeq1c8CL9az5=zkEvRAmgdawXxCN6zf8_3rk605uVcEqrBSEQ@mail.gmail.com
On Tue, Jul 3, 2012 at 6:01 AM, Ed Avis <perlbug-followup@perl.org> wrote:
>
> I suggest a variant which performs the substitution and returns
> either the new string, or undef if no match.  Suppose the modifier
> /R is used for this purpose.  Then

Yes, but what if the original string was undef?  (warnings aside)  We
can't use a value to signal an exception in a function that takes a
value and returns a value.

Even if semantics could be worked out (die unless match?) I agree with
Ricardo that it's not worth another modifier.

I do think the documentation might need to reflect this issue and
perhaps add the suggestion to do it the old way if the success of the
match is important.

-- David

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About