Christopher Spears wrote:
I'm trying to automate g++ through a Perl script. Here is what I have written so far:

#!/bin/perl -w
use strict;

my $counter;
$counter = 0;

for (my $i = 0; $i < @ARGV; $i++) {
    $counter++;
}

You don't need a loop for that as an array in scalar context returns the number of elements in the array:

my $counter = @ARGV;


if ($counter == 0) {

And you don't really need $counter either.

if ( @ARGV == 0 ) {


    print "Not enough arguments!";
    print "Usage: ./cedit somefile.C++";
    print "Usage (optional): ./cedit somefile.C++
outputfile";

Why not just die() or exit()?

@ARGV or do {
    print <<USAGE;
Not enough arguments!
Usage: ./cedit somefile.C++
Usage (optional): ./cedit somefile.C++ outputfile
USAGE
    exit 1;
    };


} elsif ($counter == 1) {
system "g++", (first invocation argument);

my $compiler = 'g++';

system( $compiler, @ARGV ) == 0 or die "system $compiler @ARGV failed: $?";


How do I call individual arguments from the @ARGV
array?  Basically, the usage of the script (called
cedit) is:

$./cedit somefile.C++

or

$./cedit somefile.C++ outputfile

The first argument is the .C++ file to be compiled,
and the second argument is the name of the .exe file.

The string 'somefile.C++' will be in $ARGV[0] and the string 'outputfile' will be in $ARGV[1]



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to