Dear Monks

Following the suggestions I had from this node, I started coding a one liner but I can't get it to work.

The problem: I have a UNIX alias file and I want to modify only root's alias, and only if it is different from a predefined one. For example:

To test if I well understanded the lesson, I created a file containing...

root: admin@somewhere.here root: someone@somewhere.else any: anybody@anywhere.else

...and wrote a regular expression that I would eventually put into an s/// operator; I expected it to match just the second line, but the one-liner below...

perl -ne '/^root:\s*(?!admin@somewhere.here)/ and print' alliases

actually outputs:

root: admin@somewhere.here root: someone@somewhere.else

which looks quite odd to me, since I expected the first line not to match. I also tried quoting the @ sign with a backslash, \Q...\E or useing strict: no way. More oddly (to me), if I add a \s*$ at the end of the regex to match any whitespace between the address and the end of line, then no line matches!!!

I am getting a little confused, where am I doing wrong?

Thanks in advance, and thanks to everyone that answered to the original post

Ciao!
--bronto


The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
--John M. Dlugosz

In reply to On zero-width negative lookahead assertions by bronto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.