Plankton has asked for the wisdom of the Perl Monks concerning the following question:
Dear wise Monks,
I have been using a package I wrote like so ...
I would run my script and get output of "yeah!". The code for MyModule is a file MyModule.pm. It declares an array that is global inside the module. Something like this ...$ cat myscript.pl #!/usr/bin/perl -w use strict; ... use lib('.'); use MyModule; ... my $thingy = new MyModule ( 'thing2' ); print "yeah!\n" if $thingy->is_thing(); print "boo!\n" unless $thingy->is_thing();
I decided to move the module in side my script like so I commented out the lines like so ...$ cat MyModule.pm package MyModule; use strict; my @things = ( 'thing1' , 'thing2' , 'thing3' , ); sub is_thing { my $self = shift; my $t = $self->{'thing'}; return grep /^$t$/, $things; } ... 1;
... then I made a new script like so ...#use lib('.'); #use MyModule;
Now my script behaves as if @things is empty. What did I do wrong?$ cat myscript.pl MyModule.pm > newscript.pl $ ./newscript.pl $ boo!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Defining a package inside my script?
by ikegami (Patriarch) on Jan 30, 2009 at 23:51 UTC | |
by Plankton (Vicar) on Jan 31, 2009 at 00:19 UTC | |
|
Re: Defining a package inside my script?
by chromatic (Archbishop) on Jan 31, 2009 at 01:14 UTC | |
|
Re: Defining a package inside my script?
by targetsmart (Curate) on Jan 31, 2009 at 05:32 UTC | |
|
Re: Defining a package inside my script?
by Anonymous Monk on Jan 31, 2009 at 14:39 UTC |