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

checking syntax on multiple files

by xorl (Deacon)
on Jan 09, 2013 at 19:11 UTC ( #1012548=perlquestion: print w/replies, xml ) Need Help??
xorl has asked for the wisdom of the Perl Monks concerning the following question:

I'm using a Makefile to install multiple perl scripts. Before the scripts get installed I want to do a perl -c on them.

So my Makefile looks something like:

install: foo bar perl -c $^ $(INSTALL) $^ /usr/local/bin

Unfortunately the output indicates that it only checked foo and not bar.

Is there some way to make perl check all the files given to it or do I need to come up with some other way to do this in the Makefile?

Thanks in advance

Edit: Thanks to blue_cowdawg and Anon Monk for coming up with this solution:

install: foo bar for pl in $^; do perl -c -Mstrict $$pl || exit 1; done $(INSTALL) $^ /usr/local/bin

Replies are listed 'Best First'.
Re: checking syntax on multiple files
by blue_cowdawg (Monsignor) on Jan 09, 2013 at 19:44 UTC

    $ cat Makefile all: for pl in $^ ;\ do \ perl -c $$pl ;\ done

    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

      Thanks, but it isn't quite right.

      if has a problem but is ok, it doesn't stop the install

      Using the filenames from my question. Foo has a syntax error while bar is a ok. This proceeds to install the files when I want to prevent that:

      install: foo bar for pl in $^; do perl -c -Mstrict $$pl; done $(INSTALL) $^ /home/ltharris/tests/makestuf /installdir
      Any other suggestions? Thanks in advance.

        Make only cares about the exit status of the shell; the shell eats them in the for loop. Try perl -c -Mstrict $$pl || exit 1

        (I'm not a make wizard but I might try to create a "perl -c" target for each of the files in question. Well, a transformation rule perhaps. No idea on how to achieve that...)

Re: checking syntax on multiple files
by tobyink (Abbot) on Jan 10, 2013 at 09:02 UTC

    Save this tiny script as perl-checkall...

    #!/usr/bin/env perl for (@ARGV) { die "Not oll korrect!\n" if system $^X, '-c', $_; } exit(0);

    Now, in Makefile...

    install: foo bar perl-checkall $^ $(INSTALL) $^ /usr/local/bin
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1012548]
Approved by philipbailey
and John Coltrane plays...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2018-05-21 23:43 GMT
Find Nodes?
    Voting Booth?