in reply to Re: Junking excess string.. junk with s///.
in thread Junking excess string.. junk with s///.

I didn't think you were serious, but you included those "tips"...

• For the part after the first \n, we match it, but not capturing it, so used ?:

So why group it at all? $var =~ s/^(.*?)\n.*/$1/s;

• make the entire string matched, so that the entire string will be substituted (in your original code, only the part before first \n is matched, and then that part is substituted with itself, so nothing is done);

Since we aren't doing anything with the first part of the string, it seems pointless to capture it at all. This:

$var =~ s/\n.*//s;
does the trick just fine. But... the OP already came upon that solution and said so in his node. My tip: either do it that way or match what you want and reassign. No point in obfuscating unnecessarily.

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

Replies are listed 'Best First'.
Re: Re: Re: Junking excess string.. junk with s///.
by SavannahLion (Pilgrim) on Oct 17, 2003 at 01:46 UTC
    Cool great. I really appreciated the lessons from both sides. The code by pg requires a bit more reading on my part, but otherwise it's been very informative.

    I honestly don't think I would've thought that that was how the Regex behaved. I'm still new with the idea of Regex since doing anything similar with any other language would involve writing about a hundred lines of code to accomplish the same thing.

    Is it fair to stick a link to my site here?

    Thanks for you patience.