Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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.

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
    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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://183628]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2018-06-19 16:34 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (114 votes). Check out past polls.