Hi,
I am working on a perl script, were a program is given a file, another file and a deviation (a number) as input on the command line. I also wants the program to complain when its too many arguments , it should just be to filenames followed by a number!!!

I have done that but it will not work probably :


#!/usr/bin/perl -w

use strict;

my ($file1, $file2, $deviation) = @ARGV ;

sub usage {
my ($msg) = @_;
print "$msg \n\n" if defined $msg;
print "Usage: project.pl <file1> <file2> <deviation>\n";
exit;
}

&usage if ( scalar @ARGV != 3){
else {
die "Too many arguments\n";
}

__END__

thanx alot :)

this part of your code isn't correct, the syntax is bad.

&usage if ( scalar @ARGV != 3){
else {
die "Too many arguments\n";
}

try like this:

use strict;
if (scalar @ARGV != 3) {
    die "Wrong number of arguments\n";
}
my ($file1, $file2, $deviation) = @ARGV;

Thanx alot for ur help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.