Re: Undefined subroutine - newbie problem
by tobyink (Canon) on Aug 14, 2012 at 10:44 UTC
|
| [reply] [d/l] [select] |
|
|
Thank You all for reply; so:
1. generate_throws_simple consists of:
sub generate_throws_simple {
for(my $i = 0; $i < $main::b; $i++)
{
push(@main::wyniki, int(rand($main::a)+1));
}
}
1;
2. modules::gts or rather just gts - wrong copy/paste, but gts module file is in main folder as well
3. UNFORTUNATELY, I need to use "require" instead of "use" in that exercise;
is it possible? if yes, how should I do that? | [reply] [d/l] |
|
|
require Foo; import Foo; should have roughly the same effect as use Foo.
Or better, BEGIN { require Foo; import Foo; } should have exactly the same effect as use Foo.
But other than as a lesson in how use works under the hood, I'm not sure why any exercise would insist that you employ require rather than trusty old use.
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
| [reply] [d/l] [select] |
|
|
|
|
package modules::gts;
And:
package gts;
It's important that the package name on that package line, and the package name you call import on match exactly (and case-sensitively!)
If you've still not gotten it working, please post the exact and complete source code of all three files, including their file names and paths.
If you keep only providing partial information about your problem, the best we can do is guess.
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
| [reply] [d/l] [select] |
|
|
|
|
|
|
use Module VERSION LIST
use Module VERSION
use Module LIST
use Module
use VERSION
Imports some semantics into the current package from the named
module, generally by aliasing certain subroutine or variable
names into your package. It is exactly equivalent to
BEGIN { require Module; Module->import( LIST ); }
except that Module must be a bareword.
So you might try calling the import method for the package.
Alternatively, you can fully-qualify the call to include the package name, like: modules::gts::generate_throws_simple().
...roboticus
When your only tool is a hammer, all problems look like your thumb. | [reply] [d/l] [select] |
|
|
|
|
Re: Undefined subroutine - newbie problem
by DrHyde (Prior) on Aug 14, 2012 at 10:44 UTC
|
'Exporter' works by creating an import method in your module. That method is called when you use your module, but not when you merely require it.
Compare require and use.
| [reply] [d/l] [select] |
Re: Undefined subroutine - newbie problem
by cheekuperl (Monk) on Aug 14, 2012 at 11:36 UTC
|
package Abc;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(simple);
sub simple
{
print "\nThis is package Abc and function is simple() \n";
}
1;
and this is code that uses this package:
use Abc;
simple();
| [reply] [d/l] [select] |
|
|
thank you, I have done like that in last exc, but now I am obliged to use "require" :(
| [reply] |
|
|
require Abc;
Abc->import();
simple();
| [reply] [d/l] |
|
|
|
|
Re: Undefined subroutine - newbie problem
by locked_user sundialsvc4 (Abbot) on Aug 14, 2012 at 12:05 UTC
|
An “extreme fast Perl workshop?” (blink...)
“Ordered to” finish a few programs ...
“For a positive grade?” What is this, high school?
No, it’s probably the beginnings of what we call a “death march,” only sugar-coated and draped in quasi-athletic jerseys. In the real world, you don’t get brownie points for doing work “quickly.” Your work will be in production for a dozen years so it must be done well. If the company is pressuring you to learn how to sling-out garbage “quickly,” then very quietly but very quickly look for another job. One that provides professional training but without the jock-strap expectations and misguided pressures. If you survive in such a place for more than a year (and they probably calculate that only a small percentage of you actually will ...), then you will be doomed to maintain that code.
“It takes three times as long to do it wrong.” If you are in a situation that emphasizes “speed,” either so that you “do not fail” or in order to prove what a whatever-you-think-you-are you are, instead of teaching you how to produce real quality, then you are in a lose-lose situation that they write books about. It takes time to learn how to do this well. Make sure that they are guiding you toward realistic and sustainable expectations.
| |
|
|
well probably you much misunderstood me; it is just Perl basics training and much of the exc is done by me, was quite easy for me and after classes and manual reading wasn't problematic for me;
but there are higher graded solutions and my goal is to finish them, but I found that problem on my way and I need help.
| [reply] |
|
|
Help you will certainly find here in abundance. Your problem is a missing use statement, methinks. In one module you must say what is exported; in its clients, you must tell Perl to use it.
There are wretched situations out there just like the one I described, especially for “captive audiences” in foreign countries on work-visas. I feared that you had become caught in one... The word, “extreme™” has become to me a bellwether of abusive practices. If false alarm, great.
| |
Re: Undefined subroutine - newbie problem
by spadacciniweb (Curate) on Aug 14, 2012 at 10:43 UTC
|
| [reply] |