Solved

Module definition problem

Posted on 2002-07-20
2
199 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Connecting to linux server using Net::Telnet module 25 220
How to strip .csv from file name 9 78
PERL variable conundrum 9 89
Vb script to unzip a files and rename the files 12 97
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

895 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now