develooper Front page | perl.perl5.porters | Postings from June 2008

Re: Empty regex

Thread Previous | Thread Next
From:
Ævar Arnfjörð Bjarmason
Date:
June 18, 2008 22:56
Subject:
Re: Empty regex
Message ID:
51dd1af80806182256i21db0f64wbc3c73da732e3714@mail.gmail.com
On 6/19/08, alfie@share-house.com.au <alfie@share-house.com.au> wrote:
>> It's easy to generate a warning for such code, whether it is a good
>> idea to do so is a different matter entirely.
>>
>
> Why wouldn't it be a good idea? I've just been burned. I'm sure a hell of
> a lot of others have too. Seeing as MJD created that RFC in 2000 shows
> even he might have been burned.

What I meant is that it's trivial to implement but that I didn't have
an opinion one way or the other on whether it should be in core, sorry
if I gave you the wrong impression.

> Can somebody show me when current behavior of /$empty/ would *ever* be a
> good idea? I just don't get it. if I do:
>
>   if ( $string =~ /$possible_empty/ ) {
>     ...
>   }
>
> when $possible_empty *is* empty, I *want* to test as empty, meaning *do
> exactly* the same as split //. I don't understand why split() has this
> only exception... if it was a good idea at the time for split, why not for
> everything!

I read this over multiple times and I still have no idea what you
mean, if $possible_empty is the empty string you want $string to match
only if it's the empty string?

// is the empty or NOTHING pattern, it matches everything because
everything contains a bit of nothing:) split is special cased so it'll
match nothing at position 0, internally advance the match position,
match again at position 1 and so forth.

Thread Previous | Thread Next


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