Solved

Module definition problem

Posted on 2002-07-20
2
208 Views
Last Modified: 2010-03-05
I'm trying to define a module:

package Foo;

use strict;

require Exporter;

our @ISA = qw(Exporter);
our @EXPORT = qw(bar);
our $VERSION = "1.0";

sub bar() {
    my $val = shift;

    print $val;
}

1;

However when I try to use the bar function as follows:

use strict;

use lib 'E:/Programming/Perl/libs';
use Foo;

bar("Test");

I get the following error:

Too many arguments for Foo::bar at test.pl line 6, near ""Test")"
Execution of test.pl aborted due to compilation errors.

What's going on here?
0
Comment
Question by:derekl
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 100 total points
ID: 7167243
You used the prototype bar() which means that bar has no arguments.
You probably wanted either

sub bar($) {
    my $val = shift;
    print $val;
}

or

sub bar {
    my $val = shift;
    print $val;
}
0
 

Author Comment

by:derekl
ID: 7167261
Thank I would have stared at that for 4 or 5 more hours before picking it up.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question