<?xml version="1.0" encoding="windows-1252"?>
<node id="183628" title="Re: win2unix" created="2002-07-20 13:33:31" updated="2005-07-03 03:46:01">
<type id="11">
note</type>
<author id="183106">
Ionitor</author>
<data>
<field name="doctext">
Just a few comments on the code:
&lt;br&gt;&lt;code&gt;if(&lt;IN&gt;=~m/(^#!+?perl+?)/){
    $out.=$1;
}
&lt;/code&gt;&lt;p&gt;
First, this appears to try to remove the first line if it isn't a perl shebang line.  If you're trying to remove a blank line at the beginning, testing for whitespace would probably be easier and safer.  However, if you really want to discard any 1st line that isn't a perl shebang, there's a couple problems with your regex.  The pattern &lt;code&gt;+?&lt;/code&gt; causes minimal matching of at least one character, where the character matched is immediately before the &lt;code&gt;+?&lt;/code&gt;.  In other words, here are a few things your regex will match:
&lt;br&gt;&lt;code&gt;#!perl
#!!!!!!!perlllllll
#!perl -w
&lt;/code&gt;
In the last case, &lt;code&gt;#!perl&lt;/code&gt; is the only thing captured by the parens in the regex.  Note that your code will not match &lt;code&gt;#!/usr/bin/perl&lt;/code&gt;.&lt;p&gt;
What you probably want is:
&lt;br&gt;&lt;code&gt;if(&lt;IN&gt;=~m/(^#!.*?perl.+)/){
    $out.="$1\n";
}
&lt;/code&gt;&lt;p&gt;
This way, your code will match and capture &lt;code&gt;#!perl&lt;/code&gt; (used often in Windows programs, esp. by Activestate), &lt;code&gt;#!/usr/bin/perl&lt;/code&gt;, and &lt;code&gt;#!/usr/bin/perl -w&lt;/code&gt;.  Additionally, the new line that the period does not capture will be added back on, without a ^M.&lt;p&gt;

&lt;strong&gt;Update:&lt;/strong&gt;&lt;br&gt;
That should be:
&lt;br&gt;&lt;code&gt;if(&lt;IN&gt;=~m/(^#!.*?perl.*)/){
    $out.="$1\n";
&lt;/code&gt;&lt;p&gt;
Forgot to replace the other "+".</field>
<field name="root_node">
183567</field>
<field name="parent_node">
183567</field>
</data>
</node>
