Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: win2unix

by Ionitor (Scribe)
on Jul 20, 2002 at 17:33 UTC ( #183628=note: print w/ replies, xml ) Need Help??


in reply to win2unix

Just a few comments on the code:

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:

#!perl #!!!!!!!perlllllll #!perl -w
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.

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 "+".


Comment on Re: win2unix
Select or Download Code
Re: Re: win2unix
by ackohno (Scribe) on Jul 21, 2002 at 04:25 UTC
    Thanks for calling my attention to that, I didn't notice...
    Your's didn't exactly work that well, but I came up with something that does: m/(^#!.*perl.*)/ this matches just about everything i could think of just now. Sure, it still matches things like #!apflperladsf, but who cares :o).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://183628]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (15)
As of 2014-04-18 20:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (471 votes), past polls