in reply to win2unix
if(<IN>=~m/(^#!+?perl+?)/){ $out.=$1; }
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 +? causes minimal matching of at least one character, where the character matched is immediately before the +?. In other words, here are a few things your regex will match:
In the last case, #!perl is the only thing captured by the parens in the regex. Note that your code will not match #!/usr/bin/perl.#!perl #!!!!!!!perlllllll #!perl -w
What you probably want is:
if(<IN>=~m/(^#!.*?perl.+)/){ $out.="$1\n"; }
This way, your code will match and capture #!perl (used often in Windows programs, esp. by Activestate), #!/usr/bin/perl, and #!/usr/bin/perl -w. Additionally, the new line that the period does not capture will be added back on, without a ^M.
Update:
That should be:
if(<IN>=~m/(^#!.*?perl.*)/){ $out.="$1\n";
Forgot to replace the other "+".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: win2unix
by ackohno (Scribe) on Jul 21, 2002 at 04:25 UTC |