• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

Syntax Problem

I'm receiving this error:

syntax error at salesad.pl line 50, near "))
"
  (Might be a runaway multi-line )) string starting on line 34)

...and can't figure it out... can someone help?
#!/usr/bin/perl

sub valueSort {
        $carMake{$a} cmp $carMake{$b};
}

%carMake = (
                "FORD" => "Ford Motor Company",
                "GM" => "General Motors",
                "CHRYS" => "Chrysler Corporation",
                "OTHER" => "a company (Not Listed)",
                );      

print "WELCOME to the Auto-something Information Requestor\n";
$now = localtime();
print "Today\'s date is ", $now, "\n";
print "Please enter the following information:\n";
print "Your name: ";
$name = <STDIN>;
# $number = read(STDIN, $firstName);
Sleep(1);
print "Would you like more information?  (Y or N): ";
$ans = <>;
if ($ans eq Y or y)
{
print "What is your Phone Number (xxx-xxx-xxxx): ";
$phone = <>;
print "\n";
print "Your address:\n";
print "\tStreet: ";
$stAddress = <>;
print "\tCity, State, Zip: ";
$cSZ = <>;
print "Information will be sent to your address at\n";
printf "\t% s", $stAddress;
printf "\t% s\n", $cSZ;
}
print "\n";
print '"Car makes" information available:', "\n";
print "_________________________\n";     
foreach $key (sort valueSort(keys(%carMake))) {
   printf "% -2s\|%s\n", $key, $carMake{$key};
   print "_________________________\n";     
}
print "\n";
print "What is the \Uname\E of the car brand you are interested in? ";
$carType = <>;
chomp $carType;
$carType = uc($carType);
print 'The car is manufactured by ', qq/"$carMake{$carType}."/;
print "\n\n";
print "Thank you, ", $name, "for your interest.\n\n";

Open in new window


0
Member_2_4213139
Asked:
Member_2_4213139
  • 2
1 Solution
 
Member_2_4213139Author Commented:
The error occurs on 50 - 8 (I removed some comments before posting) and so the 34 is -8, too... so the 50 is now "42" and the 34 is "26" ...
0
 
farzanjCommented:
On line 24 you can have something like

if ($ans eq Y or $ans eq 'y')
0
 
Member_2_4213139Author Commented:
THANK YOU!  Another EXCELLENT job!!!
0
 
wilcoxonCommented:
First, I would strongly suggest using "strict" and "warnings".  These will greatly help with debugging your code.  Here is a cleaned up and corrected version (assuming I didn't make any typos).

As farzanj noted, the only real problem I saw with your code was the "if ($and eq Y or y)".
#!/usr/bin/perl

use strict;
use warnings;

# must declare vars with strict (my or our)
my %carMake = (
                "FORD" => "Ford Motor Company",
                "GM" => "General Motors",
                "CHRYS" => "Chrysler Corporation",
                "OTHER" => "a company (Not Listed)",
              );      

# moved after the declaration to avoid error
sub valueSort {
        $carMake{$a} cmp $carMake{$b};
}

print "WELCOME to the Auto-something Information Requestor\n";
my $now = localtime();
print "Today\'s date is ", $now, "\n";
print "Please enter the following information:\n";
print "Your name: ";
my $name = <STDIN>;
# my $number = read(STDIN, $firstName);
Sleep(1);
print "Would you like more information?  (Y or N): ";
my $ans = <>;
if ($ans eq 'Y' or $and eq 'y')
{
    print "What is your Phone Number (xxx-xxx-xxxx): ";
    my $phone = <>;
    print "\n";
    print "Your address:\n";
    print "\tStreet: ";
    my $stAddress = <>;
    print "\tCity, State, Zip: ";
    my $cSZ = <>;
    print "Information will be sent to your address at\n";
    printf "\t% s", $stAddress;
    printf "\t% s\n", $cSZ;
}
print "\n";
print '"Car makes" information available:', "\n";
print "_________________________\n";     
foreach my $key (sort valueSort(keys(%carMake))) {
   printf "% -2s\|%s\n", $key, $carMake{$key};
   print "_________________________\n";     
}
print "\n";
print "What is the \Uname\E of the car brand you are interested in? ";
my $carType = <>;
chomp $carType;
$carType = uc($carType);
print 'The car is manufactured by ', qq/"$carMake{$carType}."/;
print "\n\n";
print "Thank you, ", $name, "for your interest.\n\n";

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now