Link to home
Start Free TrialLog in
Avatar of Member_2_4213139
Member_2_4213139Flag for United States of America

asked on

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


Avatar of Member_2_4213139
Member_2_4213139
Flag of United States of America image

ASKER

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" ...
ASKER CERTIFIED SOLUTION
Avatar of farzanj
farzanj
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
THANK YOU!  Another EXCELLENT job!!!
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