I dont know if this is a dumb question, but I am unable to move ahead and need help -
There is a perl module called Header.pm which was written by someone else. I am trying to write a simple perl script which uses a function provided by the module. The function has been exported by the module and in my perl script I have a "use Header". I also have a "use lib <path to the module>" to be sure that the module is located. However, despite this, it keeps giving an error that an undefined subroutine is being called.
Is this because I have not installed the module but merely copied it to my local dir ? How can I install this perl module (I dont have a makefile.pl)
Check whether you need to import any symbols. Sometimes, a set of subroutines is always exported; while at other times you need to specify what you need to import at the "use" statement.
For example, if you look at the examples at the top of Carp - perldoc.perl.org, the "croak" method is exported automatically, while "cluck" needs an explicit import.
For what needs to be imported or not, you'll need to read the module source code, or you ask the maintainer of that module. Typically, if you don't mind the hassle, you can always specify the full package name (e.g. Carp::cluck("XXXX") in the above example) and avoid all those import mess. In my opinion, this is usually a good thing.
It works if you "use Carp;" and Carp::cluck("xx") (but not just cluck("xx")). Mind the case.
I showed you the docs from the Carp module to tell you there are modules that require explicit import vs. auto-import. I didn't mean you need to use it in your programs.
No, you should not need to make any Makefile.PL if you are not planning to release it for distribution. Putting in current directory will always work. I have made numerous classes before but I have never found the need to create any Makefile.PL.
Either you post your module source code, or you ask the maintainer of the module how to use that module, because the maintainer should tell you how to use it (either through existing docs, test cases etc.)
I had tried with the correct case - sorry about the typo.
Ok here is my perl script:
##################
#! /usr/bin/perl
BEGIN { push @INC,"/ws/testdir" };
use strict;
use Header qw( wrap_package );
use Env;
#print "$ENV{'PATH'}";
sub test {
print "test"
}
my $iso="stage.iso";
my $product="final.iso";
my $MAGIC_NUM="abcd";
test
my ( $header_filename ) = Header::wrap_package(
$iso,
$product,
$MAGIC_NUM,
10000,
"KEY_TLV_PACKAGE_COMPATIBILITY",
"FRU_TEST_TYPE"
)
########################
Here is the module:Header.pm
package MCP::Header;
use strict;
use warnings;
use Data::Dumper;
use Digest::SHA;
use File::Basename;
use File::Spec::Functions qw( rel2abs );
You should put Header.pm inside a subdirectory named exactly MCP. That is say if you place your code in /tmp/something.pl, there should be a /tmp/MCP/Header.pm file or it will not work.