http://www.perlmonks.org?node_id=940717

I've been using a lot of Java for school. Because I run Linux, this means going into the command line and running javac, sometimes up to 5 different files for one program. And if I have one thing wrong, I have to do it all over again. So finally, I got tired of it and wrote this:

#!/usr/bin/perl my $file; my $last = 1; while (@ARGV and $last) { last if ($ARGV[0] =~ /^\-a$/); $file = shift; die "$file\.java does not exist\!\n" unless (-e $file."\.java"); system ("javac", $file.".java"); } shift if !@ARGV; exec ("java", $file, @ARGV);

For every argument, provided that the file exists, it compiles the .java, the runs the last file it compiles. If you have "-a", it passes the arguments after that to the program! I know it's not much, but it's my first legitimate, made for use Perl script, so I thought I'd post it.

Now, if only I could tell it to not run if I get a compile error...

UPDATE: I got the code to die if there was a compile error, but still print out the error messages. Now it looks like this:

#!/usr/bin/perl my $file; while (@ARGV and $last) { if ($ARGV[0] =~ /^\-a$/) { shift; last; } $file = shift; die "$file\.java does not exist\!\n" unless (-e $file."\.java"); $error= system("javac", $file."\.java"); } die "Compiling error, could not run!\n" if ($error); shift if !@ARGV; exec ("java", $file, @ARGV);