http://qs321.pair.com?node_id=390074

bronto has asked for the wisdom of the Perl Monks concerning the following question:

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