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