Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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]
marto sighs
[choroba]: marto I don't know them, but their fb page has a black avatar and background...
[marto]: #deletefacebook

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2018-03-22 09:39 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (273 votes). Check out past polls.