Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl Modules

Status
Not open for further replies.

Verbetex

Programmer
Apr 18, 2002
18
0
0
GB
I've got a script which i execute, and it has the line:
use IndexHandler;

I have created the package IndexHandler.pm, and when I run my script, it loads it fine, and I can run one of the subroutines in IndexHandler.pm.

However, I need to pass 3 variables to the subroutine. I've tried this by putting:

IndexHandler::saveInvertedToFile(%wordList, "$stop", "$stem");

and in my package, I have:

my(%hash, $stop, $stem) = @_;

But when i try to use the variables, they have no value.

Am I doing it the right way??

Any help appreciated
 
You could pass these variables to the subs in your module. Mike

"Experience is the comb that Nature gives us, after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
You have to pass %wordlist by reference (or put it at the end of the argument list instead of the beginning). when you have a statement like
Code:
my(%hash, $stop, $stem) = @_;
the %hash is gobbling up all the variables from @_. If you were to print out %hash from this function you would see a key/value pair for whatever was contained in $stop and $stem. you need to pass the values as
Code:
IndexHandler::saveInvertedToFile(\%wordList, "$stop", "$stem");

# and read them as

my ($hashref, $stop, $stem) = @_;

# if you really want a hash then you can assign it after you read in the argument list

my %hash = %$hashref;
Or change the ordering of the values passed putting the %hash at the end. Passing the reference is better (and faster).

jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top