Tin-Shan Chau <[EMAIL PROTECTED]> wrote:
> I have a module as follows:
> 
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> package Test;
> require Exporter;
> our @ISA = qw(Exporter);
> our @EXPORT = qw(print_name print_test);
> sub print_test() {
>    print "test\n";
> }
> sub print_name() {
>    my $file = shift;
> 
>    print "$file\n";
> }
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> When I tried to run the following:
> 
> use Test;
> print_test();
> 
> It worked as expected.  But when I tried to run this:
> 
> use Test;
> file = shift;
> print_name($file);
> 
> PERL complained "Too many arguments for Fred::print_name ..."
> 
> The difference seems to be the presence or absence of an argument.  
> Can anyone help me to get around this problem?
> 
> Thanks in advance for your help!
> 

You declared both subs with empty "prototypes":

  sub print_name() {
                ^^

Which tells perl that the subroutine doesn't have
any parameters, and leads to an error when you try
to call it with an argument.

Check 'perldoc perlsub'.

And to fix it, just use this instead:

  sub print_name {

-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to