Help with Perl Module


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Perl Module
# 1  
Old 11-13-2008
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 !!
# 2  
Old 11-13-2008
is this a module from cpan? you check file Header.pm to know this.
if yes, you can install it as:
Code:
perl -MCPAN -e "install 'Some::Module'"

# 3  
Old 11-13-2008
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.
# 4  
Old 11-13-2008
Didnt work

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.
# 5  
Old 11-13-2008
Quote:
Originally Posted by NewDeb
I had already tried the carp::cluck("xx") and it doesnt work.
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.)
# 6  
Old 11-13-2008
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:Smilieumper;

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 ?
# 7  
Old 11-14-2008
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;
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl script module

I took the copy of the production module to the home directory and executing the module. one of the test prdmsk.pm module is present in the home directory ctskk. would like to know whether the below syntax is correct. use strict; use lib "/home/ssprod/ctskk"; use lib::Prdmsk; ... (0 Replies)
Discussion started by: ramkumar15
0 Replies

2. Shell Programming and Scripting

Perl module

I am recieiving an out of memory issue in my perl module while updating the records in the oracle table. Let me know what are the check or troubleshoot steps need to be done from my end to fix the issue. (1 Reply)
Discussion started by: ramkumar15
1 Replies

3. Shell Programming and Scripting

Perl SSH without a perl module

I'm trying to create a perl script that will do 1 SSH session, but be able to write multiple commands to the session and receive multiple outputs. I know there are modules out there like Net:SSH::Perl, but I'm not allowed to use it. I was thinking of doing something like an open3 on an ssh... (4 Replies)
Discussion started by: mrwatkin
4 Replies

4. Shell Programming and Scripting

calling perl subroutine from perl expect module

All, Is it possible to call a subroutine from the perl expect module after logging to a system that is within the same program. My situation is I need to run a logic inside a machine that I'm logging in using the expect module, the logic is also available in the same expect program. Thanks,... (5 Replies)
Discussion started by: arun_maffy
5 Replies

5. Shell Programming and Scripting

Which Perl Module to use?

Hi, I need to read an excel binary file and write the data to a text file. Is it possible using Spreadsheet-ParseExcel-0.58 ? If not, is there any module available in CPAN to do this? Thanks, Js (1 Reply)
Discussion started by: jisha
1 Replies

6. Shell Programming and Scripting

Perl Module

Hi, Please help me!! Im wondering if anyone can help me with a problem i have with some perl modules. My problem is: I'm trying to connect remote host to a unix box from a windows machine. So i'm developing an application to do this. I'm programming it in perl with tcl/tk Gui interface.... (13 Replies)
Discussion started by: Phi01
13 Replies

7. UNIX for Dummies Questions & Answers

help in writing perl module

Hi i have written a perl script which was then converted to perl module by me. it works as expected. but i have to put it on many servers so i want to build a package for it. i dont know how to do that. just to check i copied perl module in "lib" directory which is working. ( directly copied... (1 Reply)
Discussion started by: zedex
1 Replies

8. Shell Programming and Scripting

Perl Module Help

Hi All, I am using a perl module Win32::AdminMisc in my perl script. When i running in activestate perl v5.10.0 it shows folling error --- Can't locate loadable object for module Win32::AdminMisc in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) at example.pl Please reply. ... (7 Replies)
Discussion started by: suprcool
7 Replies

9. Shell Programming and Scripting

perl module question

Couple questions on perl module.. 1)where is the best place on web where it tells you what modules can do? For example, use Text::Autoformat Where is the best place on line or via command line to find the exact capability of autoformat? 2)Is there already a perl module to read *.cap... (1 Reply)
Discussion started by: convenientstore
1 Replies

10. Shell Programming and Scripting

Replace Perl Module name in all Perl scripts

I want to replace a Perl module name in all my Perl Scripts in the cgi-bin directory. How is it possible? I have the following statement in my scripts use myUtil; I want to change it to use myUtil777; Regards, Rahul (2 Replies)
Discussion started by: rahulrathod
2 Replies
Login or Register to Ask a Question