Loading ...
Sorry, an error occurred while loading the content.

Creating and using a module

Expand Messages
  • John Mayson
    I am trying to create and use a Perl module. I m starting out very simple just as an example. Anyone know why it doesn t work? The .pm file are in the @INC.
    Message 1 of 4 , Dec 1, 2001
    • 0 Attachment
      I am trying to create and use a Perl module. I'm starting out very simple just as an example. Anyone know why it doesn't work? The .pm file are in the @INC.

      _____________________uniden.pm____________________
      package uniden;

      use strict;

      $VERSION = "0.00";

      sub allclear {

      print "AC\n";

      }

      __END__



      _________________uniden.pl______________________
      #!/usr/bin/perl

      use lib uniden;

      uniden::allclear();
      __END__

      --
      John Mayson KC4VJO Linux/Perl/HP-UX/ICT
      Austin, Texas 78729 30.4560N 97.7851W
      jmayson.ee92@... http://www.nyx.net/~jmayson
    • gordon stewart
      ... I am trying to create and use a Perl module.  I m starting out very simple just as an example.  Anyone know why it doesn t
      Message 2 of 4 , Dec 1, 2001
      • 0 Attachment
        --- John Mayson <kc4vjo@...> wrote:
        <HR>
        <html><body>
        <tt>
        I am trying to create and use a Perl module.  I'm
        starting out very simple just as an example. 
        Anyone know why it doesn't work?  The .pm file
        are in the @INC.
        <

        For one thing, I dont see any


        print "Content-type: text/html\n\n";
        print "<HTML><BODY>\n";


        lines in it, - As far as i know, you always need to
        put a content-type line in a script.

        I havnt done any modules that just "print" something,
        but try looking at :-

        http://homepages.slingshot.co.nz/~gordon52/modules.htm

        which shows you a simple module, that adds a value to
        whatever number you send it.

        G.


        =====
        G.
        New Zealand chat & Discussion group email
        new_zealand-help@yahoogroups.com for details.

        http://shopping.yahoo.com.au - Yahoo! Shopping
        - Get organised for Christmas early this year!
      • Jenda Krynicky
        To: PBML From: John Mayson Date sent: Sat, 01 Dec 2001 12:24:53 -0600 Send reply
        Message 3 of 4 , Dec 1, 2001
        • 0 Attachment
          To: PBML <perl-beginner@yahoogroups.com>
          From: John Mayson <kc4vjo@...>
          Date sent: Sat, 01 Dec 2001 12:24:53 -0600
          Send reply to: perl-beginner@yahoogroups.com
          Subject: [PBML] Creating and using a module

          > I am trying to create and use a Perl module. I'm starting out very
          > simple just as an example. Anyone know why it doesn't work? The .pm
          > file are in the @INC.
          >
          > _____________________uniden.pm____________________
          > package uniden;
          >
          > use strict;
          >
          > $VERSION = "0.00";
          >
          > sub allclear {
          >
          > print "AC\n";
          >
          > }
          >
          > __END__

          You get something like "uniden.pm did not return a true value"
          right?

          The last command in a module must evaluate to a true value.

          Usualy you just end the modules with
          1;
          but you can do some tests during the module loading and return a
          false to report failure.

          I don't remember seeing a module that'd do that though.

          Jenda


          =========== Jenda@... == http://Jenda.Krynicky.cz ==========
          There is a reason for living. There must be. I've seen it somewhere.
          It's just that in the mess on my table ... and in my brain.
          I can't find it.
          --- me
        • jonathan.mark2@dyncorp.com
          use lib LIST adds the directories specified in LIST to Perl s search path. Since in your case uniden is a module and not a directory you get an error. If
          Message 4 of 4 , Dec 2, 2001
          • 0 Attachment
            'use lib LIST' adds the directories specified in LIST to Perl's
            search path. Since in your case uniden is a module and not a
            directory you get an error.

            If you remove the keyword lib and simply say 'use uniden' then Perl
            looks for uniden.pm in the same directory as uniden.pl. I fixed your
            script and it works. In fact, you can see your script's output at
            http://www.jonathanmark.com/tempo3.pl







            --- In perl-beginner@y..., John Mayson <kc4vjo@q...> wrote:
            > I am trying to create and use a Perl module. I'm starting out very
            simple just as an example. Anyone know why it doesn't work? The .pm
            file are in the @INC.
            >
            > _____________________uniden.pm____________________
            > package uniden;
            >
            > use strict;
            >
            > $VERSION = "0.00";
            >
            > sub allclear {
            >
            > print "AC\n";
            >
            > }
            >
            > __END__
            >
            >
            >
            > _________________uniden.pl______________________
            > #!/usr/bin/perl
            >
            > use lib uniden;
            >
            > uniden::allclear();
            > __END__
            >
            > --
            > John Mayson KC4VJO Linux/Perl/HP-UX/ICT
            > Austin, Texas 78729 30.4560N 97.7851W
            > jmayson.ee92@g... http://www.nyx.net/~jmayson
          Your message has been successfully submitted and would be delivered to recipients shortly.