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:
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.$var =~ s/\n.*//s;
-sauoq "My two cents aren't worth a dime.";
In reply to Re: Re: Junking excess string.. junk with s///.
by sauoq
in thread Junking excess string.. junk with s///.
by SavannahLion
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |