Solved

extra print commands

Posted on 2003-10-28
6
182 Views
Last Modified: 2010-03-05
Im not sure how to work the question. But im learning CGI and i saw the command

print p("<b>Thank you for your order $name!</b>") ;

what does the methond p() do? And are there any other like this one? IE i saw qq() on one question and it said it is for double qoutes.

thanks
0
Comment
Question by:ocsurf
6 Comments
 
LVL 3

Expert Comment

by:prady_21
ID: 9638305
i think it is an error unless the experts think otherwise

infact it would be helpful if you post the full code where you saw the  command
0
 
LVL 1

Author Comment

by:ocsurf
ID: 9638316
#!/usr/local/bin/perl -w


use CGI qw(:standard);

print header,

start_html("Ice Cream Stand"), h1("Ice Cream Stand");
if (param()) { # the form has already been filled out
    my $who = param("name");
    my $flavor = param("flavor");
    my $scoops = param("scoops");
    my $taxrate = 1.0743;
    my $cost = sprintf("%.2f", $taxrate * (1.00 + $scoops * 0.25));
    print p("Ok, $who, have $scoops scoops of $flavor for \$$cost.");
} else { # first time through, so present clean form
    print hr(); # draw a horizontal rule before the form
    print start_form();
    print p("What's your name? ", textfield("name"));
    print p("What flavor: ", popup_menu("flavor", ['mint','cherry','mocha']));
    print p("How many scoops? ", popup_menu("scoops", [ 1..3 ]));
    print p(submit("order"), reset("clear"));
    print end_form(), hr();
}
print end_html;
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9638438
If you're using the CGI module, the 'p' function just puts the text in a <p> tag pair.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Accepted Solution

by:
fantasy1001 earned 125 total points
ID: 9639638
About print p,
this is the cgi.m shortcut key for adding the <p> pair. You can also print others tag like this for example: print br(..., print hr(...), print h2("this is font2")

About qq:
By default the print function, and most other Perl functions, use the " sign to deliminate. Using the qq command, we can pick a replacement for the " sign so we can use the " sign inside the print without needing to escape it.

Instead of writing:

  print "\"Hello\", Joe said.";
You could also write:

  print qq!"Hello", Joe said.!;

Thanks & Cheers

0
 
LVL 20

Expert Comment

by:jmcg
ID: 9639894
An interesting thing about most of the html shortcut functions supplied by CGI.pm — p( ), b( ), h1( ), h2( ), etc — is that they are are all generated from the same template using the autoloader.

Fantasy has answered both parts of your question. I suggest you accept his answer. Of course, we're ready to explain more if need be.
0
 
LVL 1

Author Comment

by:ocsurf
ID: 9642203
Thanks all for the help
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question