A couple minor comments. First, your loop through the file - if you found what you want, you probably should break out. Second, rather than foreach, you probably want while - no point in reading in a huge file and then looping through it.

Then I have to wonder why you're looking through the file at all. You only need to check the first line. And you probably should make the same check that perl does - that it starts with "#!" and has "perl" somewhere in the line:

open( my $input, "<", $file ) or return; # can't read, can't test. P +erhaps mark as a failure? my $line = <$input>; return unless $line =~ /^#!\s*(.*perl\S*)/; my $desired_interpreter = $1 close( $input );

Now I've captured the perl that this file wants to use, so we can use it in the system command.

If you want to support pathological cases where there is leading cruft, you'll need to scan the rest of the file looking for the #!.*perl line, and then use the -x option to the perl interpreter - but I don't think that doing this in an automated manner is wise. So I suggest just looking at the first line, and discarding the rest.


In reply to Re: Perl test - Make sure all perl files will compile by Tanktalus
in thread Perl test - Make sure all perl files will compile by skx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.