bronto has asked for the wisdom of the Perl Monks concerning the following question:
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:
- root: firstname.lastname@example.org is OK and should be left untouched
- root: email@example.com is NOT OK and should be modified
- Any non-root alias should be left untouched
To test if I well understanded the lesson, I created a file containing...
root: firstname.lastname@example.org root: email@example.com any: firstname.lastname@example.org
...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*(?!email@example.com)/ and print' alliases
root: firstname.lastname@example.org root: email@example.com
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
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