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

Creating package...

Expand Messages
  • Gordon Stewart
    Hi - ive got the following package set up under the :- perl/lib/my/debtextract.pm file.. The Script works (ive used it, But i want to convert it into a
    Message 1 of 8 , Sep 3, 2001
    View Source
    • 0 Attachment
      Hi - ive got the following 'package' set up under the :-

      perl/lib/my/debtextract.pm file..

      The Script works (ive used it, But i want to convert it into a package - So other scripts can use it.

      Basically, I want to pass a variable $ird to the script, & the result, is @araa

      Heres my PM file :-

      --------------
      package debtextract;

      require 5.002;

      # The following require can't be removed during maintenance
      # releases, sadly, because of the risk of buggy code that does
      # require Carp; Carp::croak "..."; without brackets dying
      # if Carp hasn't been loaded in earlier compile time. :-(
      # We'll let those bugs get found on the development track.
      require Carp if $] < 5.00450;

      sub go {
      my ($ird) = @_;


      <cut>

      return @araa;
      }
      1;


      --------

      Heres the script that is using / calling the PM file :-

      ----------------------------------------------

      #!/usr/bin/perl
      use CGI::Carp qw(fatalsToBrowser);use CGI 'param';use my::debtextract;

      my $start = 0;
      my $ird = param 'ird';

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

      @araa = go($ird);

      foreach $line(@araa){
      print "$line<BR>\n";
      }
      ----------------------------------------------

      of course - It produces an error -

      Undefined subroutine &main::go called at C:\Savant\Root\cgi-bin\irdradc\view2.cgi line 13.


      Do i change line 13 - Or my PM file ?

      Havnt used / designed PM files before.


      G.
    • Greg
      ... Me neither, but try: @araa = &go($ird); Greg
      Message 2 of 8 , Sep 4, 2001
      View Source
      • 0 Attachment
        --- In perl-beginner@y..., "Gordon Stewart" <Gordon.Stewart@i...>
        wrote:

        > Havnt used / designed PM files before.

        Me neither, but try: @araa = &go($ird);

        Greg
      • gordon stewart
        ... Thanks - nearly bed-time, I ll try it tomorow at work, & tell you then if it goes... (cant bring the data-file home). G. ===== G. Stewart New Zealand chat
        Message 3 of 8 , Sep 4, 2001
        View Source
        • 0 Attachment
          --- Greg <webmaster@...> wrote:
          > --- In perl-beginner@y..., "Gordon Stewart"
          > <Gordon.Stewart@i...>
          > wrote:
          >
          > > Havnt used / designed PM files before.
          >
          > Me neither, but try: @araa = &go($ird);
          >
          > Greg

          Thanks - nearly bed-time, I'll try it tomorow at work,
          & tell you then if it goes...

          (cant bring the data-file home).

          G.


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

          http://travel.yahoo.com.au - Yahoo! Travel
          - Got Itchy feet? Get inspired!
        • Jenda Krynicky
          ... Since the file is .../lib/my/debtextract.pm the package should be my::debtextract . The reason is when you write use Foo::Bar; perl does this (pseudo
          Message 4 of 8 , Sep 4, 2001
          View Source
          • 0 Attachment
            > Hi - ive got the following 'package' set up under the :-
            >
            > perl/lib/my/debtextract.pm file..
            >
            > Basically, I want to pass a variable $ird to the script, & the
            > result, is @araa
            >
            > Heres my PM file :-
            >
            > --------------
            > package debtextract;


            Since the file is ".../lib/my/debtextract.pm" the package should be
            "my::debtextract".

            The reason is when you write

            use Foo::Bar;

            perl does this (pseudo code!)

            #========
            $mod = 'Foo::Bar';
            $mod =~ s{::}{/}g; # on a Mac it would be s{::}{:}g I believe

            foreach $dir (@INC) {
            if (-e "$dir/$mod.pm") {
            load_and_compile "$dir/$mod.pm";
            last;
            }
            }

            Foo::Bar::import();
            #========

            >
            > sub go {
            > my ($ird) = @_;
            >
            >
            > <cut>
            >
            > return @araa;
            > }
            > 1;

            You are not exporting the function. This way you will only be able
            to call it like
            my::debtextract::go()

            You should add

            require Exporter;
            @ISA = qw(Exporter);
            @EXPORT = qw();
            @EXPORT_OK = qw(go);

            into the module. You will be able to export the function to the
            "calling" package :

            #!/usr/bin/perl -w
            use my::debtextract qw(go);
            @res = go( 'home' );

            HTH, Jenda


            == Jenda@... == http://Jenda.Krynicky.cz ==
            : What do people think?
            What, do people think? :-)
            -- Larry Wall in <199808071736.KAA12738@...>
          • Daniel Gardner
            GS Havnt used / designed PM files before. there s some stuff you might find interesting here: http://www.perldoc.com/perl5.6/pod/perlmodlib.html ta, daniel
            Message 5 of 8 , Sep 4, 2001
            View Source
            • 0 Attachment
              GS> Havnt used / designed PM files before.

              there's some stuff you might find interesting here:

              http://www.perldoc.com/perl5.6/pod/perlmodlib.html

              ta,
              daniel
            • Gordon Stewart
              ... ... Thanks - nearly bed-time, I ll try it tomorow at work, & tell you then if it goes...
              Message 6 of 8 , Sep 4, 2001
              View Source
              • 0 Attachment
                --- Greg <webmaster@...> wrote:
                >> --- In perl-beginner@y..., "Gordon Stewart"
                <Gordon.Stewart@i...>
                wrote:

                > Havnt used / designed PM files before.

                >Me neither, but try: @araa = &go($ird);

                > Greg

                Thanks - nearly bed-time, I'll try it tomorow at work,
                & tell you then if it goes...
                <

                Nope - Ive got these lines (& a bit more) :-
                but it comes up with an error :-

                Global symbol "@araa" requires explicit package name at C:/Savant/perl5/lib/my/debtextract.pm line 23.

                Global symbol "@araa" requires explicit package name at C:/Savant/perl5/lib/my/debtextract.pm line 27.

                Global symbol "@araa" requires explicit package name at C:/Savant/perl5/lib/my/debtextract.pm line 28.

                Etc.,.

                What . can this mean ?
                G.

                -------------------------
                @araa=<INF>;

                close INF;

                pop (@araa); # gets rid of the start / end 'half-lines'
                shift (@araa);


                foreach $line (@araa){

                -------------------------
              • Bob Jacobson
                # this may help you out... # here s a real simple example of using a package variable... #test.pl package test; use strict; # always a good idea # all vars
                Message 7 of 8 , Sep 5, 2001
                View Source
                • 0 Attachment
                  # this may help you out...
                  # here's a real simple example of using a package variable...
                  #test.pl
                  package test;
                  use strict; # always a good idea

                  # all vars will now be held in the test symbol table
                  $test::var1 = "whatever";

                  package main;

                  # you are now in the main package
                  print STDOUT "Output = $test::var1 \n";

                  # if you try your var this way it will give you the error that you are
                  getting
                  #print STDOUT " Output = $var1 \n";

                  # you can then break the package out to another file if you
                  # want, just make sure to include: use test in your calling program;

                  -----Original Message-----
                  From: Gordon Stewart [mailto:Gordon.Stewart@...]
                  Sent: Tuesday, September 04, 2001 5:31 PM
                  To: perl-beginner@yahoogroups.com
                  Subject: Re: [PBML] Re: Creating package...


                  --- Greg <webmaster@...> wrote:
                  >> --- In perl-beginner@y..., "Gordon Stewart"
                  <Gordon.Stewart@i...>
                  wrote:

                  > Havnt used / designed PM files before.

                  >Me neither, but try: @araa = &go($ird);

                  > Greg

                  Thanks - nearly bed-time, I'll try it tomorow at work,
                  & tell you then if it goes...
                  <

                  Nope - Ive got these lines (& a bit more) :-
                  but it comes up with an error :-

                  Global symbol "@araa" requires explicit package name at
                  C:/Savant/perl5/lib/my/debtextract.pm line 23.

                  Global symbol "@araa" requires explicit package name at
                  C:/Savant/perl5/lib/my/debtextract.pm line 27.

                  Global symbol "@araa" requires explicit package name at
                  C:/Savant/perl5/lib/my/debtextract.pm line 28.

                  Etc.,.

                  What . can this mean ?
                  G.

                  -------------------------
                  @araa=<INF>;

                  close INF;

                  pop (@araa); # gets rid of the start / end 'half-lines'
                  shift (@araa);


                  foreach $line (@araa){

                  -------------------------






                  Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
                • Bob Jacobson
                  # this may help you out... # here s a real simple example of using a package variable... #test.pl package test; use strict; # all vars will now be held in the
                  Message 8 of 8 , Sep 5, 2001
                  View Source
                  • 0 Attachment
                    # this may help you out...
                    # here's a real simple example of using a package variable...
                    #test.pl
                    package test;
                    use strict;

                    # all vars will now be held in the test symbol table
                    $test::var1 = "whatever";

                    package main;
                    # you are now in the main package
                    print STDOUT "Output = $test::var1 \n";

                    # if you try to print $var1 this way it will give you the error that you are
                    getting
                    #print STDOUT " Output = $var1 \n";

                    # you can then break the package out to another file if you
                    # want, just make sure to include: use test or require test in your calling
                    program;

                    -Bob

                    -----Original Message-----
                    From: Gordon Stewart [mailto:Gordon.Stewart@...]
                    Sent: Tuesday, September 04, 2001 5:31 PM
                    To: perl-beginner@yahoogroups.com
                    Subject: Re: [PBML] Re: Creating package...


                    --- Greg <webmaster@...> wrote:
                    >> --- In perl-beginner@y..., "Gordon Stewart"
                    <Gordon.Stewart@i...>
                    wrote:

                    > Havnt used / designed PM files before.

                    >Me neither, but try: @araa = &go($ird);

                    > Greg

                    Thanks - nearly bed-time, I'll try it tomorow at work,
                    & tell you then if it goes...
                    <

                    Nope - Ive got these lines (& a bit more) :-
                    but it comes up with an error :-

                    Global symbol "@araa" requires explicit package name at
                    C:/Savant/perl5/lib/my/debtextract.pm line 23.

                    Global symbol "@araa" requires explicit package name at
                    C:/Savant/perl5/lib/my/debtextract.pm line 27.

                    Global symbol "@araa" requires explicit package name at
                    C:/Savant/perl5/lib/my/debtextract.pm line 28.

                    Etc.,.

                    What . can this mean ?
                    G.

                    -------------------------
                    @araa=<INF>;

                    close INF;

                    pop (@araa); # gets rid of the start / end 'half-lines'
                    shift (@araa);


                    foreach $line (@araa){

                    -------------------------






                    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
                  Your message has been successfully submitted and would be delivered to recipients shortly.