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.
In reply to Creating hashes into a module. by vitojph
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |