Here is the code that I currently have. Running on Perl v5.8.9.
#!/usr/bin/perl
# Prompts the user for their desired configuration
print "\n";
print "Please type BB for breadboard, or ACU for the Audio Control Unit.\n";
print "Do you want a BB or ACU version of alarm programmer: ";
$a = <STDIN>;
"\n";
# print "You have selected the $a configuration";
# print "\n";
if($a == "ACU"){
print("Initiating alarm programmer for ACU...\n");
}else{
print("Initiating alarm programmer for breadboard...\n");
}
Here is some sample output:
C:\Users\U157280\Documents\Alarm Programmer>PerlAutonomy.pl
Please type BB for breadboard, or ACU for the Audio Control Unit. Do you want a BB or ACU version of alarm programmer: ACU
Initiating alarm programmer for ACU...
C:\Users\U157280\Documents\Alarm Programmer>PerlAutonomy.pl
Please type BB for breadboard, or ACU for the Audio Control Unit. Do you want a BB or ACU version of alarm programmer: BB
Initiating alarm programmer for ACU...
As you can see, it selects ACU for both even though the statements appear to be correct.
Any help you can provide would be greatly appreciated. Please let me know if I can answer any more questions, but I assume this should be a quick fix.
Thanks again.
CodePudding user response:
Try this:
#!/usr/bin/perl
# Prompts the user for their desired configuration
print "\n";
print "Please type BB for breadboard, or ACU for the Audio Control Unit.\n";
print "Do you want a BB or ACU version of alarm programmer: ";
$a = <STDIN>;
"\n";
chomp($a);
# print "You have selected the $a configuration";
# print "\n";
if($a eq "ACU"){
print("Initiating alarm programmer for ACU...\n");
}else{
print("Initiating alarm programmer for breadboard...\n");
}
You had 2 issues, first, = is assignment not comparison. Second, you had a newline at the end of your input that you weren't accounting for. The chomp() gets rid of the newline, and the eq does string comparison.