Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

First attempt at a module

by sulfericacid (Deacon)
on May 21, 2004 at 07:03 UTC ( #355197=perlquestion: print w/ replies, xml ) Need Help??
sulfericacid has asked for the wisdom of the Perl Monks concerning the following question:

I've read quite a few links already on modules but I'm still not getting quite what I'm looking for. For now, I'm just trying to setup a simple module that does SOMETHING, in this case just print "HELLO WORLD". No errors are appearing at run time but nothing prints, can someone explain why?

Essentially I'm looking to have something setup like LWP::Simple where I can use things such as

my $this = get($that);
where get() could be collect() or anything. That's what I'm trying to get a module to be able to do incase anyone has suggestions on how that is done. I ripped open Simple.pm and needless to say that didn't explain much :)

Both mod.pl and TestPrint.pm are sitting on my desktop so they're both in the same place. UPDATE----------
As suggested by two people, I tried using both of these and the lack of results are the same:
&test_print;
test_print();
/UPDATE----------

TestPrint.pm package TestPrint; use Exporter; @ISA = 'Exporter'; @EXPORT_OK = qw(test_print); use strict; sub test_print { print "hello world"; return; } 1; __END__ mod.pl #!/usr/bin/perl use warnings; use strict; use TestPrint qw(test_print); &test_print; # seems to do nothing test_print(); # also seems to do nothing


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

Comment on First attempt at a module
Select or Download Code
Re: First attempt at a module
by ColtsFoot (Chaplain) on May 21, 2004 at 07:13 UTC
    You should try and call the sub from your mod.pl script
    mod.pl #!/usr/bin/perl use warnings; use strict; use TestPrint qw(test_print); test_print();
    The result of running mod.pl will be the output "hello world" on STDOUT
    Hope this helps
Re: First attempt at a module
by matija (Priest) on May 21, 2004 at 07:34 UTC
    Are you sure that your module is being loaded correctly? I don't see a 'use lib "somedirectory";' in your mod.pl. What happens when you go into the script with the debugger and step into the subroutine calls? What do you see?
      I am not sure of anything at this point. I am not using "use lib" though as it's not giving me an error saying it cannot find the module like it typically does if it can't find it. So I assume it's finding the module just fine just on the account of it not telling me about it.

      I have tried: use lib "/Documents and Settings/Sulfericacid/Desktop/"; but the results haven't changed. (both script and .pm are on Desktop).



      "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

      sulfericacid
        "$word is nothing more than $definition blah blah blah"

        weenie
        I think Richard Harris put it best in "Silence of the lambs":'When you assume you make an ass out of u and me'.

        Don't assume, check. If you can't think of any other way to check, make a deliberate syntax error in your module, and see if you get an error message. If you don't there must be some other module with the same name in your @INC.

Re: First attempt at a module
by monkey_boy (Curate) on May 21, 2004 at 08:12 UTC
    Hi , ive cut n pasted your example & it works perfectly.. What type of machine are you on & what perl version?
    I should really do something about this apathy ... but i just cant be bothered
Re: First attempt at a module
by ambrus (Abbot) on May 21, 2004 at 11:55 UTC

    Perl searches the module in the current directory, not the directory where the srcipt resides. Make sure to cd to the directory, and call perl mod.pl from there. The module and the code you've included work for me, except for that test_print does not print a newline. If, by any chance you have a \r in your shell prompt (assuming you're not on windows; yes, I was so stupid once to put a \r in my prompt), you won't see the output.

      Thanks for your help everyone. This was seriously bugging me! I renamed the mod and all the innards to a different name I KNEW wasn't used and it did as it was supposed to. There must have been something called TestPrint.pm already.

      Now that it's working, it's time to go play and break it again :)



      "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

      sulfericacid

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://355197]
Approved by greenFox
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2014-08-30 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (290 votes), past polls