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

Re: Empty regex

Thread Previous | Thread Next
From:
Abigail
Date:
June 25, 2008 09:36
Subject:
Re: Empty regex
Message ID:
20080625133319.GB8495@almanda
On Wed, Jun 18, 2008 at 10:54:48PM -0600, 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.

In general, I don't think "I've just been burned" any reason in itself
to add warnings to existing constructs that don't warn currently. I know
it's popular to say "Hey, this feature has worked like this for over a
dozen years, but this morning, I got burned, so now I think someone else
should add a warning", but IMO, that generally is a bad idea.

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

Considering that "split //" splits on empty strings between characters, and
=~ matches, I've no idea what you mean by "I want to do it the same as split".
The best I can thing of is that's a complicated way of writing

    if (length ($string) > 1) {
        ...
    }

but then, IMO, you should just say that.

> Sorry for my tone. I'm just a bit depressed that I fell into the booby
> trap :)


Well, I don't think that a warning for /$var/ where $var is empty is a bad
thing, but I think we should not change the meaning. 


Abigail

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