Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Easy Script Editor

by pixel (Scribe)
on Oct 05, 2001 at 19:17 UTC ( [id://117013]=note: print w/replies, xml ) Need Help??


in reply to Easy Script Editor

I agree completely with ajt's worries about the security of what you're doing, but I'd also like to raise a couple of points about your use of CGI.pm.

CGI.pm has two APIs - an object oriented interface and a functional interface. Although the majority of references seem to use the OO interface, I think that the functional interface is simpler to use.

In the functional interface you import a set of functions into your program's namespace. You do this by passing optional arguments into the use CGI statement like this:

use CGI qw(:standard);

:standard defines a particular set of functions that will cover most of your CGI needs. Having imported the functions you can just use them without having to create an object. Like this:

use CGI qw(:standard); my $name = param('name'); print header, start_html, h1('Test Page'); print p("The name is $name"); print end_html;

On the other hand, if you use the OO interface you need to create a CGI object and then access all of the functions thru that object. Like this:

use CGI; my $q = CGI-new; my $name = $q->param('name'); print $q->header, $q->start_html, $q->h1('Test Page'); print $q->p("The name is $name"); print $q->end_html;

It's not that much more typing, but I think that the functional version looks neater.

I mention this, because you use the functional way of loading CGI.pm but then go on to use the OO interface thoughout your script. This shows that you may be slightly confused.

Oh, and one more thing about the OO interface. Using syntax like:

my $q = new CGI;

instead of

my $q = CGI->new;

Is going to work fine 999 times out of a 1000, but it can occasionally lead to very hard to track down bugs. Read what Damian Conway says about the indirect object syntax in Object Oriented Perl for a full description of the problems.

Blessed Be
The Pixel

Replies are listed 'Best First'.
Re: Re: Easy Script Editor
by George_Sherston (Vicar) on Oct 05, 2001 at 21:33 UTC
    Thanks very much for that. You're right, I have been jolly confused about the differences between the two ways of using CGI.pm, and, as you can see, got around that confusion by ignoring it. Not a good long term strategy. But I think I do now understand it rather better, and I'm most grateful.

    I must say I don't understand OO programming. And I feel I ought to, and I ought to use it for preference because it's... more advanced, grown up or something. This leads me into using it in ways I don't really understand what I'm doing - not a good thing. Perhaps I shouldn't get hung up on that, and just go with the functional approach which makes more intuitive sense to me.

    § George Sherston

      OO is good when you have lots of instances of the same class, each carrying around their own pieces of data. But in a CGI script, it's very rare that you'd have more than one CGI object - therefore I think that the OO interface is unnecessary.

      (Actually, with the functional interface, it is creating a CGI object, but you don't need to know about it.)

      Blessed Be
      The Pixel

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://117013]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-20 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found