Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Im trying to do an assingnement in PERL but when i run it has an error and it sa

ID: 3533578 • Letter: I

Question

Im trying to do an assingnement in PERL but when i run it has an error and it says :

./proj1: line 1: syntax error near unexpected token `('


the following code is this :



%hash = (

32, ' ',

33, '..--.',

39, '.----.',

44, '--..--',

46, '.-.-.-',

48, '-----',

49, '.----',

50, '..---',

51, '...--',

52, '....-',

53, '.....',

54, '-....',

55, '--...',

56, '---..',

57, '----.',

58, '---...',

61, '-...-',

63, '..--..',

65, '.-',

66, '-...',

67, '-.-.',

68, '-..',

69, '.',

70, '..-.',

71, '--.',

72, '....',

73, '..',

74, '.---',

75, '-.-',

76, '.-..',

77, '--',

78, '-.',

79, '---',

80, '.--.',

81, '--.-',

82, '.-.',

83, '...',

84, '-',

85, '..-',

86, '...-',

87, '.--',

88, '-..-',

89, '-.--',

90, '--..'

);

print "Please, choose one: ";

print "1. Convert Latin to Morse Code ";

print "2. Convert Morse Code to Latin ";

$choice = <>;

if ($choice == 1)

{

        print "Enter file name ";

        $file1 = <>;

        open (file, $file1);

        while ($b = read file,$c,1)

        {

                print $hash{ord(uc($c))};

                print " ";

        }

}

elsif ($choice == 2)

{

        print "Enter file name ";

        $file1 = <>;

        open (file, $file1);

               

                %reverse = reverse %hash;

        while ($b = read file,$c,1)

        {

                        if ($c ne " ")

                        {$string = $string . $c; $space= "";}

                elsif (($c eq " ") or eof(file))

                        {

                        if ($space eq " ") {print " ";}

                                                else

                                {

                                                               

                                                                foreach $key (keys %reverse)

                                                                {

                                                                        if ($key eq $string){ print lc(chr($reverse{$key}));};

                                                                };

                                                               

                                $string = "";

                                $space = " ";

                                }

                        };

        };

}

else {print "No such option exists! "; print "Please, restart the program";}

print " ";

close (file);

what can i do ?

Explanation / Answer

The solution seems to be:

based on my intuitive understanding of what that code intended - but I can't be certain till you provide some more context (what does validate() return, what does list() mean?)

If you meant list() as a means to force $val and @value into a list, you merely need to enclose both in parenthesis: ($val, @value) to do that