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);

In reply to Java Auto-Compile by JediMasterT

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.