perl:regarding commas and semicolons

Discussion in 'Programming' started by nix, Oct 17, 2009.

Thread Status:
Not open for further replies.
  1. nix

    nix Senior Member

    Joined:
    Oct 5, 2004
    Messages:
    648
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Bangalore
    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 
    
     
  2. lucifer_is_back

    lucifer_is_back New Member

    Joined:
    Oct 17, 2008
    Messages:
    124
    Likes Received:
    0
    Trophy Points:
    0
    if i remember it rite then , is used to separate the arguments and ; is used for statement termination
     
  3. OP
    OP
    nix

    nix Senior Member

    Joined:
    Oct 5, 2004
    Messages:
    648
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Bangalore
    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.
     
  4. lucifer_is_back

    lucifer_is_back New Member

    Joined:
    Oct 17, 2008
    Messages:
    124
    Likes Received:
    0
    Trophy Points:
    0
    lol
    its simple what dont u understand
     
  5. OP
    OP
    nix

    nix Senior Member

    Joined:
    Oct 5, 2004
    Messages:
    648
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Bangalore
    ^ 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?
     
  6. lucifer_is_back

    lucifer_is_back New Member

    Joined:
    Oct 17, 2008
    Messages:
    124
    Likes Received:
    0
    Trophy Points:
    0
    because in first code snippet start_html function is passed as one of the parameters to print statement


    but in second snippet start_html function it is the last parameter
     
  7. OP
    OP
    nix

    nix Senior Member

    Joined:
    Oct 5, 2004
    Messages:
    648
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Bangalore
    ^ got it, cleared. thanks for your time, i appreciate it.
     
Thread Status:
Not open for further replies.

Share This Page