janmejay
02-25-2008, 01:44 PM
I am a newbie to Perl programming. Couple questions, need help!
Copied below script from a book and tried to run it, however got following error
+++++++++++
sunp5:/export/home/janmejay-> /bin/perl joke.pl
Bareword found where operator expected at joke.pl line 15, near "print "What"
(Might be a runaway multi-line "" string starting on line 11)
(Do you need to predeclare print?)
syntax error at joke.pl line 15, near "print "What disappears "
Search pattern not terminated at joke.pl line 15.
+++++++++++
2nd question - why do I have to write /bin/perl filename everytime I want to run a script. Why not just with filename? If I give only filename, it gives
ksh: joke.pl: cannot execute
++++++++++++
Here is my code -
========================
sunp5:/export/home/janmejay-> cat -n joke.pl
1 #!/usr/bin/perl -w
2 #
3 # JokeMachine.pl
4 clear_the_screen();
5 clear_the_screen();
6 $reply = "";
7 while ($reply ne 'yes'){
8 print 'Would you like to hear a joke? (yes/no):';
9 chomp($reply = <STDIN>);
10 if ($reply ne 'yes') {
11 print "Hum...Perhaps you misunderstood.\n\";
12 }
13 }
14 clear_the_screen();
15 print "What disappears the moment you say its name?";
16 chomp($reply =<STDIN>;
17 if ($reply ne 'silence') {
18 print "Sorry, Wrong answer. Think about it and try again later.\n\n";
19 } else {
20 print "Yes, that is right. Well done!\n\n";
21 }
22 sub clear_the_screen {
23 for ($i=0; $i < 25; ++$i){
24 print "\n";
25 }
26 }
========================
Copied below script from a book and tried to run it, however got following error
+++++++++++
sunp5:/export/home/janmejay-> /bin/perl joke.pl
Bareword found where operator expected at joke.pl line 15, near "print "What"
(Might be a runaway multi-line "" string starting on line 11)
(Do you need to predeclare print?)
syntax error at joke.pl line 15, near "print "What disappears "
Search pattern not terminated at joke.pl line 15.
+++++++++++
2nd question - why do I have to write /bin/perl filename everytime I want to run a script. Why not just with filename? If I give only filename, it gives
ksh: joke.pl: cannot execute
++++++++++++
Here is my code -
========================
sunp5:/export/home/janmejay-> cat -n joke.pl
1 #!/usr/bin/perl -w
2 #
3 # JokeMachine.pl
4 clear_the_screen();
5 clear_the_screen();
6 $reply = "";
7 while ($reply ne 'yes'){
8 print 'Would you like to hear a joke? (yes/no):';
9 chomp($reply = <STDIN>);
10 if ($reply ne 'yes') {
11 print "Hum...Perhaps you misunderstood.\n\";
12 }
13 }
14 clear_the_screen();
15 print "What disappears the moment you say its name?";
16 chomp($reply =<STDIN>;
17 if ($reply ne 'silence') {
18 print "Sorry, Wrong answer. Think about it and try again later.\n\n";
19 } else {
20 print "Yes, that is right. Well done!\n\n";
21 }
22 sub clear_the_screen {
23 for ($i=0; $i < 25; ++$i){
24 print "\n";
25 }
26 }
========================