Solved

extra print commands

Posted on 2003-10-28
6
175 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

773 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