my "dr" hosts are my disaster/recovery hosts that i don't use on a daily basis...the other ones are production hosts that i'm using on a daily basis.<br><br>
<div><span class="gmail_quote">On 10/11/07, <b class="gmail_sendername">Garrett Goebel</b> <<a href="mailto:ggoebel@goebel.ws">ggoebel@goebel.ws</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">In order to fix your regex you'll need to tell us the difference<br>between somehostpm1 and dr-somehostpm1.
<br><br>Will a "good" somehostpm1 never be preceeded by 'dr-'? If so...<br><br># Shot at adhering to Perl Best Practices<br>open my($file), '<', '/etc/hosts';<br>while (my $line = <$file>) {
<br> if ($line =~ /(?<!dr-)\S+pm1/) {<br> print $line;<br> }<br>}<br><br># Quick'n Dirty<br>open FILE, '</etc/hosts';<br>map { print if /(?<!dr-)\S+pm1/ } <FILE>;<br><br>I haven't tested it... perhaps it'll work.
<br><br>(?<!pattern) is a zero width negative look behind assertion. I.e.<br>it'll match anything that isn't preceeded by the pattern without<br>including it in the match.<br><br>Garrett<br><br>On Oct 11, 2007, at 2:44 PM, Emmanuel Mejias wrote:
<br><br>> trying to grep out some info from my /etc/hosts file...just to get<br>> more practice with Perl and well for my personal pleasure, too.<br>><br>> #!/usr/bin/perl<br>><br>> open (FILE, "/etc/hosts");
<br>> @lines = <FILE>;<br>> close (FILE);<br>><br>> foreach $line (@lines){<br>> if ($line =~ /pm1/){<br>> print $line;<br>> }<br>> }<br>><br>> the problem with this is that it's printing out some hosts that i
<br>> don't want that also have pm1 at the end.<br>><br>> somehostpm1 but it also gets my dr hosts (dr-somehostpm1)<br>><br>> thoughts?<br>><br>> by the way, i had to jump the wifes car so i ended up missing out
<br>> on the meeting. gonna try to make the next one for sure, though.<br>><br>> _______________________________________________<br>> kc mailing list<br>> <a href="mailto:kc@pm.org">kc@pm.org</a><br>> <a href="http://mail.pm.org/mailman/listinfo/kc">
http://mail.pm.org/mailman/listinfo/kc</a><br><br></blockquote></div><br>