Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Re: An "ethical" use of dot-star ..?

by Tanalis (Curate)
on Jun 02, 2003 at 14:26 UTC ( [id://262384]=note: print w/replies, xml ) Need Help??


in reply to Re: An "ethical" use of dot-star ..?
in thread An "ethical" use of dot-star ..?

Yes.

What does that gain, though, over .*?? Is it more efficient, or is it simply avoiding the "problem" by coding round it?

Also, to reliably detect a closing tag, you need to match </. There's nothing to stop "<" from appearing in the data (in fact, it's likely for limits we impose locally on credit). The .* construct would have correctly matched "<" without terminating, and continued to match up until it found the </ of a closing tag.

I don't think I'm convinced that the alternative you suggest would have the same effect on the data, and the data that got grabbed as the .*.

-- Foxcub
#include www.liquidfusion.org.uk

Replies are listed 'Best First'.
Re: Re: Re: An "ethical" use of dot-star ..?
by fglock (Vicar) on Jun 02, 2003 at 14:42 UTC

    There is an explanation for why this is slightly better, in Death to Dot Star!.

    If you apply the change, the regex will look like:

    $example =~ /^\s*\<(\w+)\s[\w\"\=]+\>([^<]*)\<\//;

    I think it will not have a different effect on the data.

Re: Re: Re: An "ethical" use of dot-star ..?
by PodMaster (Abbot) on Jun 02, 2003 at 14:51 UTC
    use YAPE::HTML by japhy


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
    ** The Third rule of perl club is a statement of fact: pod is sexy.

Re: Re: Re: An "ethical" use of dot-star ..?
by sauoq (Abbot) on Jun 03, 2003 at 00:13 UTC
    What does that gain, though, over .*??

    It better expresses what you are actually trying to do. (I''m actually not entirely sure that's true in your case, but it may be.)

    For one, using [^<]* will match a newline. Your original regex will not. You'd have to use a /s modifier for that.

    On the other hand, using [^<]* will simply fail to match on strings like: "<inequality>X < Y</inequality>" but maybe that's fine in your case.

    By the way, yours will fail if there is a space between the '<' and the '/' in the end tag. Maybe you knew that though.... if that's what you wanted, it's fine.

    And that's really the crux of the matter. There is nothing inherently wrong in using a dot-star. It's just misunderstood so often that it's prudent to warn people about it. The other day, I recommended someone use my ($file, $ext) = /(.*)\.(.*)/; to break a filename into its base and extension. Two dot-stars for the price of one there... but — shrug — it did what he needed. The key is understanding what you need and how best to express it. Don't say "zero or more (but as few as possible) of any character except a newline" when you really mean "as many non-Less-Than characters as possible."

    -sauoq
    "My two cents aren't worth a dime.";
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://262384]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-04-19 14:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found