469,304 Members | 1,796 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,304 developers. It's quick & easy.

.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?
Mar 8 '07 #1
10 3398
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
Mar 8 '07 #2
i was asking about the second option, do we need to save the .pm files inside the bin folder??
thanks for the reply.



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
Mar 8 '07 #3
KevinADC
4,059 Expert 2GB
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.
Mar 8 '07 #4
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
Mar 8 '07 #5
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.


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
Mar 9 '07 #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.
Mar 9 '07 #7
KevinADC
4,059 Expert 2GB
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:
Expand|Select|Wrap|Line Numbers
  1. #!perl;
  2.  
  3. use strict;
  4. use Calc;
  5. my $value = math(5);
  6. print $value;
Calc.pm:
Expand|Select|Wrap|Line Numbers
  1. package Calc;
  2. use strict;
  3. require Exporter;
  4.  
  5. our @ISA    = qw(Exporter);
  6. our @EXPORT = qw(math);
  7.  
  8. sub math {
  9.    my $value = shift;
  10.    $value++;
  11.    return $value;
  12. }
  13. 1;
Mar 9 '07 #8
it does not works it gives an error saying"undefined subroutine &main::math called at value.pl line 5.


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:
Expand|Select|Wrap|Line Numbers
  1. #!perl;
  2.  
  3. use strict;
  4. use Calc;
  5. my $value = math(5);
  6. print $value;
Calc.pm:
Expand|Select|Wrap|Line Numbers
  1. package Calc;
  2. use strict;
  3. require Exporter;
  4.  
  5. our @ISA    = qw(Exporter);
  6. our @EXPORT = qw(math);
  7.  
  8. sub math {
  9.    my $value = shift;
  10.    $value++;
  11.    return $value;
  12. }
  13. 1;
Mar 9 '07 #9
KevinADC
4,059 Expert 2GB
Works OK for me.
Mar 9 '07 #10
thanks very much,program works fine.

Works OK for me.
Mar 12 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by matt | last post: by
7 posts views Thread by Joseph | last post: by
3 posts views Thread by StGo | last post: by
3 posts views Thread by Shapper | last post: by
reply views Thread by thjwong | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.