Help with Perl Module

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)

Please advise.
Thanks !!

is this a module from cpan? you check file Header.pm to know this.
if yes, you can install it as:

perl -MCPAN -e "install 'Some::Module'"

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.

First of all, thanks so much for replying.
I tried to explicitly import the function I wanted from Header.pm, but that did not help.

I had already tried the carp::cluck("xx") and it doesnt work.

Its not a CPAN module.

Should I create a makefile.pl and try to run make and make install?
I wonder what I am missing.

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 );

use Fcntl qw( :seek );

use Util::Misc;

require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw( wrap_package );
our @EXPORT_OK = qw();

<snip>
sub wrap_package {
...
}

###########

I copied Header.pm into my local directory /ws/testdir and am trying to execute the perl script to no avail.

What am I missing ?

instead of:

my ( $header_filename ) = Header::wrap_package(

try:

my ( $header_filename ) = wrap_package(

it also appears that you don't need to import the function when the module is loaded because it is exported by default:

our @EXPORT = qw( wrap_package );

So you can just do this in your main script:

use Header;

Your module file has this:

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.

Good observation, I completely missed that. But then they should be getting an error about module not in @INC instead of an undefined subrotuine.

Maybe the OP has a weird @INC or has strange ways to load modules, who knows?