Clearly, dot star is evil. The extent of its vicious machinations was just now made known to me. Because I had chanced upon the one situation to which I thought dot star was perfectly suited.

You see, I wanted to match everything. No exceptions. I wanted to slurp up the whole freakin' input. I wanted to match a certain beginning word, then match everything that followed it, and use s/// to replace just that word and one little character near the end. Instead of ending );, it was just going to end with ;.

$line =~ s/wordone\s*\((.*)\)\;//wordtwo\:$1\;/

So what had read "wordone(hello);" would now read "wordtwo:hello;" Very simple. And no matter how much was between those parentheses, I wanted it all, to just suck up the whole world.

But then my code went from suck to blow.

I thought that I had found the one good use for dot star, because I truly did want a greedy match of everything under the sun.

But dot star doesn't match newlines, it seems.

So instead of matching too much or too little, it instead matched nothing at all. Since there was no match, there was no substitution. And clearly, dot star is completely useless for anything except breaking your code.

Death to dot star! Long live ([^\)]*)!

We live in a society exquisitely dependent on science and technology, in which hardly anyone knows anything about science and technology.
- Carl Sagan

Replies are listed 'Best First'.
Re: Ode to Death to Dot Star
by broquaint (Abbot) on Nov 13, 2001 at 22:04 UTC
    You might want to try the 's' modifier on your regex
    $line =~ s/wordone\s*\((.*)\)\;//wordtwo\:$1\;/s
    And also not have b0rken regex in the first place
    $line =~ s/wordone\s*\((.*)\);/wordtwo:$1;/s;
    You're escaping characters that don't need to be escaped (i.e non-alphanumeric non-meta-characters <pant> <pant> ;).
    HTH

    broquaint

Re: Ode to Death to Dot Star
by dws (Chancellor) on Nov 13, 2001 at 22:34 UTC
    RTFM!

    It is a cardinal mistake in any language to extrapolate behavior from a few examples without having Read The Fine Manual. The docs will tell you what the special cases are. And even if you don't remember the special cases, you'll know that they are there, and then should know to re-read the docs when your code isn't behaving as expected.

    This is true with Perl; it is true with Java; and it is likely true with any other language you can name. Languages have special cases. Powerful languages like Perl are likely to have more special cases. It's frustrating to run into them, and it's embarrassing when people point you back to the documentation (it's embarrassing to me, at least), but that's just how it is.

    Read (and re-read) perlre before you try to drop your problems at dot star's door.

Re: Ode to Death to Dot Star
by monkeygirl (Pilgrim) on Nov 13, 2001 at 22:06 UTC

    If you use the /s modifier, it will treat $line as a single-line, thus allowing the dot to match newline characters.


    Sarah
    If Bill Gates can name a company after his "bedroom" problems, I can have a stupid sig that points it out.
Re: Ode to Death to Dot Star
by frankus (Priest) on Nov 13, 2001 at 22:04 UTC

    For the parsimonius: .* is dead long live .*?

    For my money there are no bad code practices just some awaiting a useful deployment ;)

    --

    Brother Frankus.

    ¤