Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Perl test - Make sure all perl files will compile

by Tanktalus (Canon)
on Jul 12, 2006 at 14:59 UTC ( #560710=note: print w/replies, xml ) Need Help??


in reply to Perl test - Make sure all perl files will compile

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.

Replies are listed 'Best First'.
Re^2: Perl test - Make sure all perl files will compile
by skx (Parson) on Jul 13, 2006 at 15:07 UTC

    ++ - Thanks!

    Amazing how obvious it sounds now you've said it.

    Steve
    --

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2021-12-01 18:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (13 votes). Check out past polls.

    Notices?