Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Undefined subroutine

by hiseldl (Priest)
on Mar 11, 2003 at 14:15 UTC ( #242032=note: print w/replies, xml ) Need Help??


in reply to Undefined subroutine

In order to use OO to it's fullest, you will need to create a constructor ('new' method) and then you can instantiate an object with your class:

package Test; ... sub new { my $self = {}; bless $self; return $self; } ... use Test; my $test_var = new Test; $test_var->Prt("This is a test in the Mod\n");

You should also take a look at perltoot which has some more details about how to create constructors.

Update: You should make sure that your module does not have the same name as an already installed module, or else you can cause yourself some unneeded confusion.

Update: why do I need to use OO stuff? You don't need to use the OO stuff. Your statement was 'Any help would be greatly appreciated' and I was simply offering another solution. Sorry for the confusion.

--
hiseldl
What time is it? It's Camel Time!

Replies are listed 'Best First'.
Re: Re: Undefined subroutine
by J9 (Beadle) on Mar 11, 2003 at 14:28 UTC
    I'll give this a bash, but I can't help wondering why I need to use OO stuff though. I just want to use a module straight like I would with
    #! /use/bin/perl use strict; use Term::ReadKey; ReadMode( "noecho"); print "Enter pwd please :"; chomp (my $pwd = <>); ReadMode ("original") ; print "\nYou typed $pwd!\n";
    where ReadMode is a subroutine in the Term::ReadKey module.
Re^2: Undefined subroutine
by zigdon (Deacon) on Mar 11, 2003 at 14:28 UTC
    Isn't a Module != Object?

    -- zigdon

      Yes, you are correct, a module is not an object, but you can use a module to instantiate an object. e.g. use MyMod; $object = new MyMod;

      --
      hiseldl
      What time is it? It's Camel Time!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://242032]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2022-05-18 14:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (71 votes). Check out past polls.

    Notices?