perl:regarding commas and semicolons

Status
Not open for further replies.

nix

Senior Member
i have inserted a program below.
as seen below, some statements use semicolons and some use commas, there seems to be no definite rule to follow, can anyone enlighten me on this? thanks...
Code:
 1 #!/usr/bin/perl
  2 use strict;
  3 use CGI':standard';
  4 if(param)
  5 {
  6         my $entry=param('entry');
  7         print header(),
  8         start_html("Program 7b"),
  9         #ignorecomment1
 10        #ignorecomment2
 11         h3("result is "),
 12         `$entry`,
 13         end_html();
 14 }
 15 else
 16 {
 17         print header(),
 18         start_html("Program 7b"),
 19         start_form(),
 20         print ("Enter a valid unix command");
 21         hr(),
 22         textfield(-name=>'entry'),
 23         submit(-value=>'submit now'),
 24         end_form(),
 25         end_html();
 26 }
Code:
 1 #! /usr/bin/perl
  2 use strict;
  3 use CGI':standard';
  4 if(param)
  5 {
  6         my $cmd=param('command');
  7         if(`$cmd`)
  8         {
  9                 print header(),
 10                 start_html();
 11                 print("Result is");
 12                 `$cmd`;
 13                 end_html();
 14         }
 15         else
 16         {
 17                 print("nothing entered");
 18         }
 19 }
 20 else
 21 {
 22         print header(),
 23         start_html(),
 24         start_form(),
 25         h4("enter valid UNIX command"),
 26         hr(),textfield(-name=>'command'),
 27         submit(-value=>'submit'),
 28         end_form(),
 29         end_html();
 30 }
 31
 
OP
nix

nix

Senior Member
thanks, but i still have not got it clearly. i guess its because i use the vi editor to type my perl programs. teacher doesnt know either. looked all over the net, but no answers. thanks anyway.
 
OP
nix

nix

Senior Member
^ well, The behavior of commas and semicolons does not seem to be consistent in my programs. As you see in the programs that I attached in the first post, "start_html" in the first program ends with a comma, but the same thing ends with a semicolon in the second program. If I edit the "start_html" in the first program to end with a semicolon, I get errors. I don't understand why. Why can't both the "start_html" statements end with a semicolon?
 

lucifer_is_back

Journeyman
because in first code snippet start_html function is passed as one of the parameters to print statement
print header(), start_html("Program 7b"),h3("result is "),`$entry`,end_html();

but in second snippet start_html function it is the last parameter
print header(),start_html();
 
Status
Not open for further replies.
Top Bottom