This script doesn't do anything, but I'm trying to get it to do it well.
It accepts arguments. If it has two arguments, it should say which is first and which is second. If it has just one argument, it should just print the first argument and print that the second is nonexistent. And if there are no arguments, it should say they are both nonexistent.
Instead, I get these errors:
Here's the script:
The errors are upset with the first two print statements. Why aren't they legit?
mt
It accepts arguments. If it has two arguments, it should say which is first and which is second. If it has just one argument, it should just print the first argument and print that the second is nonexistent. And if there are no arguments, it should say they are both nonexistent.
Instead, I get these errors:
$ perl argnames2.plx arg1 arg2
Use of uninitialized value in concatenation (.) or string at argnames2.plx line 36.
First file was
Use of uninitialized value in concatenation (.) or string at argnames2.plx line 37.
Second file was
The number of items was 2
$
Here's the script:
Code:
#!/usr/bin/perl
# matchtest.plx
use warnings;
use strict;
my $scalar1;
my $firstFile;
my $secondFile;
my @array1;
@array1 = @ARGV;
$scalar1 = @array1;
if ($scalar1 == 2) {
my $firstFile = shift @array1;
my $secondFile = shift @array1;
} else {
if ($scalar1 == 1) {
my $firstFile = shift @array1;
my $secondFile = "nonexistent";
} else {
my $firstFile = "nonexistent";
my $secondFile = "nonexistent";
}
}
print "First file was $firstFile\n";
print "Second file was $secondFile\n";
print "The number of items was $scalar1\n";
The errors are upset with the first two print statements. Why aren't they legit?
mt