Hi! And, welcome to Perl!
>
> I'm trying to automate g++ through a Perl script.
> Here is what I have written so far:
>
> #!/bin/perl -w
> use strict;
## you should:
use warnings;
## it will help you in the future
>
> my $counter;
> $counter = 0;
## With Perl, it's not really necessary to initialize this variable.
It doesn't hurt, but it's just a line you didn't need to type.
>
> for (my $i = 0; $i < @ARGV; $i++) {
> $counter++;
> }
## This whole loop is not needed. If you use the @ARGV variable in a
Scalar context, it will report how many elements it has
my $number_of_args = @ARGV;
>
> if ($counter == 0) {
> print "Not enough arguments!";
> print "Usage: ./cedit somefile.C++";
> print "Usage (optional): ./cedit somefile.C++
> outputfile";
> } elsif ($counter == 1) {
> system "g++", (first invocation argument);
>
## This can be easily re-written to simplify and make it more
understandable:
if( @ARGV ) {
## Do stuff here
} else {
die "Not enough arguments!\nUsage: $0 somefile.C++\nUsage
(optional): $0 somefile.C++ outputfile";
}
> How do I call individual arguments from the @ARGV
> array? Basically, the usage of the script (called
> cedit) is:
>
The answer to this question is two-ways.
1) you can access the specific element in the array:
my $first_arg = $ARGV[0];
my $second_arg = $ARGV[1];
2) you can shift the args off the top of the array:
my $first_arg = shift;
my $seconf_arg = shift;
There is a lot going on there. There are also numerous other ways to
get at that info. You should read up on some Perl!
> $./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.
>
Check out the Perl Documentation:
perldoc perldoc
perldoc -f shift
To be honest, I'm not sure where to send you to find out about Perl
arrays in general, or the special @ARGV array specifcally.
You can check out the perldoc FAQ for it:
perldoc -q array
--Errin
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>