Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Module questions

by costas (Scribe)
on Apr 04, 2001 at 13:12 UTC ( [id://69591]=perlquestion: print w/replies, xml ) Need Help??

costas has asked for the wisdom of the Perl Monks concerning the following question:

I am new to using modules and have a few questions.

1)Is there any way besides looking through the c:/perl folders that i can see what modules i already have installed. (eg a small script i can run).

2)How can i find out EVERYTHING a module is capable of doing.

3)How do i find out what syntax is needed in my scripts to communicate properly with a module.

for example. I have just used CGI::cookies and was suprised to see that the following code actually worked. I wouldnt have know this had i not found it in an example on the net.

my $retreived_cookie = cookie('address');


4)Why do i have to write use CGI; as well as use CGI::Cookie;. Surely just calling CGI would work as the cookie stuff is in there too.

I would appreciate any response as i am sure it would help us module beginners.

Costas

Replies are listed 'Best First'.
Re: Module questions
by davorg (Chancellor) on Apr 04, 2001 at 13:22 UTC
    1)Is there any way besides looking through the c:/perl folders that i can see what modules i already have installed. (eg a small script i can run).

    It's pretty simple to write a script using File::Find that looks at every directory in @INC and finds all the '.pm' files.

    2)How can i find out EVERYTHING a module is capable of doing).

    Well, you can find out everything the module's author wants you to know by reading the module's documentation. If you want any more, you can read the source code.

    3)How do i find out what syntax is needed in my scripts to communicate properly with a module.

    See my previous answer.

    4)Why do i have to write use CGI; as well as use CGI::Cookie;. Surely just calling CGI would work as the cookie stuff is in there too.

    You only need to use CGI. If you use the cookie function then the CGI::Cookie module is required automatically.

    You might be interested in a new book that I've just picjed up. It's called Instant Perl Modules and seems to give a good introduction to getting and installing Perl modules along with details about a number of the most useful ones.

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

Re: Module questions
by neophyte (Curate) on Apr 04, 2001 at 13:44 UTC
    Answer for question 2 + 3:
    Getting at the modules documentation is easy:
    enter perldoc CGI::cookies (or any other module name) at your command prompt

    neophyte Niederrhein.pm

Re: Module questions
by larsen (Parson) on Apr 04, 2001 at 13:47 UTC
    For what concerns your first question, you could check this thread.
      Thanks, one more questions. Is Mod-perl the same as using perl with modules (eg CGI) or is it a different concept altogether?

        mod-perl is something completely different. It's using an Apache module which embeds the Perl interpreter into your Apache executable, thereby eliminating the start-up costs of running a CGI process (amongst other things). See perl.apache.org for more details.

        --
        <http://www.dave.org.uk>

        "Perl makes the fun jobs fun
        and the boring jobs bearable" - me

Re: Module questions
by satchboost (Scribe) on Apr 04, 2001 at 20:12 UTC
    The previous answer to your fourth question was inaccurate. The reason you have to write use CGI; as well as use CGI::Cookie; is that they are separate packages. PERL doesn't do any sort of inheritance naturally for you, like C++ or JAVA. Within the executable, there is no connection between CGI and CGI::Cookie.

    That said, you can get around all of this by clever module design, which is what I suspect the author(s) of CGI did.

      But you don't have to use CGI::Cookie as CGI.pm has the following line of code in its cookie function.

      require CGI::Cookie;

      Is that "clever module design"?

      Oh, and it's "Perl", not "PERL".

      --
      <http://www.dave.org.uk>

      "Perl makes the fun jobs fun
      and the boring jobs bearable" - me

        The poster asked about mod_perl, so I'll add this:
        If you ARE using mod_perl, then in the mod_perl startup script, you'll want to include both 'use CGI' and 'use CGI::Cookie', as the cookie module does not seem to get included until runtime (after child processes are forked) even when doing 'use CGI qw(-compile :all);'.
        I tried not including CGI::Cookie and only haveing use CGI.

        Unforunately this did not work.

        It seems you have to include both.
        Fair enough. That is clever module design. I suspect that it's also common module design, but it's not something that a beginner, as the poster indicated s/he was, would think about. In addition, it's listed among the common mistakes someone from C++ would make coming to PERL(!). It's certainly not what I thought about when I first started working on modules.

        And as long as you understood what I was talking about, it could've been peRl, Per1, or PerL. *grins* I don't want to start a flamewar, but that did seem a little nitpicky.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (8)
As of 2024-03-28 11:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found