vitojph has asked for the wisdom of the Perl Monks concerning the following question:
When I code the same function into a Perl script, I get no errors and it can be used correctly. However, when I "use" the previous module and this script:package MyTools; use strict; BEGIN{ use Exporter (); use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 0.01; @ISA = qw (Exporter); @EXPORT = qw (); @EXPORT_OK = qw (loadwords); %EXPORT_TAGS = (); } sub loadwords { my @words = qw(a able about above across actually after again all) +; foreach (@words) { my $some_words{$_} = "1"; } } 1; __END__
I get a error message:#!/usr/bin/perl -w use strict; use MyTools qw(loadwords); my %somewords2; # load the words from the module &loadwords; # load the words using the function &loadwords2; print "'all' is one of my words\n" if $some_words{'all'}; print "'all' is one of my words\n" if $somewords2{'all'}; sub loadwords2 { my @words2 = qw(a able about above across actually after again all +); foreach (@words2) { $somewords2{$_} = "1"; } }
What am I doing wrong? I guess I'm not exporting any variable. Any help? Please, open my eyes ;-) Thanks a lot in advance.syntax error at MyTools.pm line 16, near "$some_words{" Compilation failed in require at ./cosa.pl line 3. BEGIN failed--compilation aborted at ./cosa.pl line 3.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Creating hashes into a module.
by broquaint (Abbot) on Feb 20, 2004 at 11:57 UTC | |
|
Re: Creating hashes into a module.
by borisz (Canon) on Feb 20, 2004 at 10:59 UTC | |
by vitojph (Acolyte) on Feb 20, 2004 at 11:12 UTC | |
by borisz (Canon) on Feb 20, 2004 at 11:52 UTC | |
by vitojph (Acolyte) on Feb 20, 2004 at 13:56 UTC | |
|
Re: Creating hashes into a module.
by pelagic (Priest) on Feb 20, 2004 at 11:31 UTC | |
by vitojph (Acolyte) on Feb 20, 2004 at 11:51 UTC | |
by pelagic (Priest) on Feb 20, 2004 at 11:55 UTC |