.pm file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tovenkatesh82
    New Member
    • Mar 2007
    • 30

    .pm file

    can somebody tell me in which folder do we save .pm files.......can we save the .pm files in the same folder where we save .pl files?
  • rahatekarabhijeet
    New Member
    • Jan 2007
    • 55

    #2
    For Same Directory:
    we can keep .pm and .pl file in same directory
    e.g;
    Example.pm
    Test_Example.pl
    these are our .pm and .pl file

    we just need to mention following thing in Test_Example.pl file,
    use Example;

    For Different Directory:
    if we want to keep .pl and .pm in different directories,
    then if you create Module directory inside your present directory to keep
    your .pm files separate,

    then you just need to provide the path for Example.pm file in Test_Example.pl by,
    use Module::Example

    here Module is directory which contains Example.pm module

    Comment

    • tovenkatesh82
      New Member
      • Mar 2007
      • 30

      #3
      i was asking about the second option, do we need to save the .pm files inside the bin folder??
      thanks for the reply.



      Originally posted by rahatekarabhije et
      For Same Directory:
      we can keep .pm and .pl file in same directory
      e.g;
      Example.pm
      Test_Example.pl
      these are our .pm and .pl file

      we just need to mention following thing in Test_Example.pl file,
      use Example;

      For Different Directory:
      if we want to keep .pl and .pm in different directories,
      then if you create Module directory inside your present directory to keep
      your .pm files separate,

      then you just need to provide the path for Example.pm file in Test_Example.pl by,
      use Module::Example

      here Module is directory which contains Example.pm module

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        You can save them almost anywhere you want. It's not necessary to save them in the cgi-bin folder. But you can if you want to.

        Comment

        • docsnyder
          New Member
          • Dec 2006
          • 88

          #5
          Originally posted by tovenkatesh82
          can somebody tell me in which folder do we save .pm files.......can we save the .pm files in the same folder where we save .pl files?
          If the pm file does not reside within the same folder as your script, ensure that the path is contained in @INC.

          Greetz, Doc

          Comment

          • tovenkatesh82
            New Member
            • Mar 2007
            • 30

            #6
            hi, i created the .pm an .pl in same folder but the program shows some compilation error......

            followin is the .pm file
            #!/usr/bin/perl;
            package calc;
            use strict;

            sub math{
            my $value=0;
            $value=$_++;
            return $value;
            }
            1;

            following is the .pl file
            #!/usr/bin/perl;
            use strict;
            use calc qw(math);
            math(5);
            print $value

            following error i get
            global symbol $value requires package name at value.pl at line 5.


            Originally posted by rahatekarabhije et
            For Same Directory:
            we can keep .pm and .pl file in same directory
            e.g;
            Example.pm
            Test_Example.pl
            these are our .pm and .pl file

            we just need to mention following thing in Test_Example.pl file,
            use Example;

            For Different Directory:
            if we want to keep .pl and .pm in different directories,
            then if you create Module directory inside your present directory to keep
            your .pm files separate,

            then you just need to provide the path for Example.pm file in Test_Example.pl by,
            use Module::Example

            here Module is directory which contains Example.pm module

            Comment

            • tovenkatesh82
              New Member
              • Mar 2007
              • 30

              #7
              can someone resolve this error......

              hi, i created the .pm an .pl in same folder but the program shows some compilation error......

              followin is the .pm file
              #!/usr/bin/perl;
              package calc;
              use strict;

              sub math{
              my $value=0;
              $value=$_++;
              return $value;
              }
              1;

              following is the .pl file
              #!/usr/bin/perl;
              use strict;
              use calc qw(math);
              math(5);
              print $value

              following error i get
              global symbol $value requires package name at value.pl at line 5.

              Comment

              • KevinADC
                Recognized Expert Specialist
                • Jan 2007
                • 4092

                #8
                You didn't need to repost this same question. The reason the code fails is because it is incomplete. There are a few ways to get it to work. Here is one way:

                main script:
                Code:
                #!perl;
                
                use strict;
                use Calc;
                my $value = math(5);
                print $value;
                Calc.pm:
                Code:
                package Calc;
                use strict;
                require Exporter;
                
                our @ISA    = qw(Exporter);
                our @EXPORT = qw(math);
                
                sub math {
                   my $value = shift;
                   $value++;
                   return $value;
                }
                1;

                Comment

                • tovenkatesh82
                  New Member
                  • Mar 2007
                  • 30

                  #9
                  it does not works it gives an error saying"undefine d subroutine &main::math called at value.pl line 5.


                  Originally posted by KevinADC
                  You didn't need to repost this same question. The reason the code fails is because it is incomplete. There are a few ways to get it to work. Here is one way:

                  main script:
                  Code:
                  #!perl;
                  
                  use strict;
                  use Calc;
                  my $value = math(5);
                  print $value;
                  Calc.pm:
                  Code:
                  package Calc;
                  use strict;
                  require Exporter;
                  
                  our @ISA    = qw(Exporter);
                  our @EXPORT = qw(math);
                  
                  sub math {
                     my $value = shift;
                     $value++;
                     return $value;
                  }
                  1;

                  Comment

                  • KevinADC
                    Recognized Expert Specialist
                    • Jan 2007
                    • 4092

                    #10
                    Works OK for me.

                    Comment

                    • tovenkatesh82
                      New Member
                      • Mar 2007
                      • 30

                      #11
                      thanks very much,program works fine.

                      Originally posted by KevinADC
                      Works OK for me.

                      Comment

                      Working...