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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem in calling custom module function 1

Status
Not open for further replies.

ranadhir

Programmer
Joined
Nov 4, 2003
Messages
54
Location
IN
I have define a custom module which contains 2 utility function to return matched/unmatched boolean.
Additionally there is a function which returns the result using these util functions.
So,if i need to filter files from a directory which are not directory themselves,i need to call
my @collfiles=modules::unixop::accumulatecoll($func,\@files,$filter) ;
where $func=\&modules::unixop::filterirrelevant;
@files contains the output of the dir command.
and $filter=DIR.
This will use the utility function filterirrelevant to return the non-dir files as a collection.
But i get an error as:
Too many arguments for modules::unixop::accumulatecoll at perlexecs\xmlfeed.pl li
ne 22, near "$filter) "
What am i doing wrong?
If i shift this function within the same unit,(rather than invoing from a module) I do not get this compilation error.
 
there is nothing technically wrong with this line:

Code:
my @collfiles=modules::unixop::accumulatecoll($func,\@files,$filter) ;

the problem must be with the function accumulatecoll() which seems to be expecting only 2 arguments. Can you post the accumulatecoll() function code?
 
The function is mentioned below.The surprising part is that if i pull in this function from the module into the unit itself(along with the util routines),i do not get any compilation errors.

sub accumulatecoll()
{

my $filterroutine=shift;
my $var=shift;
my $filter=shift;
my @contents=@$var;
my $matched;
my @collmatched;
foreach my $var (@contents)
{
next unless ($matched=&$filterroutine($var,$filter));
push(@collmatched,$matched);
}

return @collmatched;
}
 
Try
Code:
[b]my $self = shift ;[/b]
my $filterroutine=shift;
my $var=shift;
my $filter=shift;


--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
whats the first parameter (self?) for?Is it a default parameter sent to external modules?
 
Anyways,this solution does not work either.I am still getting the compilation errors when the function are called from a external module.Why is this so - is there some calling convention for external modues which i am getting wrong?
 
change this:

sub accumulatecoll()

to:

sub accumulatecoll

the first one is a prototype the second is a regular sub routine. Prototypes work a bit differently than sub routines and you rarely see them used in perl scripts. I don't know if that will cure the problem you are having but give it a try and see.
 
that worked perfectly.Thanks a lot Kevin.
Also the strange point to notice is that ,this function signature gives me a problem only when it is invoked from a separate unit.
 
yea, prototypes are a little bit tricky, just don't use them. There really is never a need to use them that I am aware of.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top