CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
help with create object

 



amy_amy
Novice

Jun 11, 2006, 10:37 AM

Post #1 of 8 (1681 views)
help with create object Can't Post

Hi I have a test class create an object:

package test;
use warnings;
our $AUTOLOAD;
sub test {
my $class = shift;
my $self = {@_};
bless ($self, $class);
print "person is created!!!\n";
return $self;
}

1;



I then created another class to call the test method:

#!/usr/bin/perl -w
#usetest.pl

use strict;
use test;


my $object = test->test(
lastname => "Jen",
FIRSTNAME => "Young",
ADDRESS => "1234 kingston street",
CITY => "New York"
);

when I run the second script, I got the following message:

Can't locate object method "test" via package "test" (perhaps you forgot to load
"test"?) at usetest.pl line 8.

Please help me, thanks


mjgray06
Novice

Jun 11, 2006, 6:45 PM

Post #2 of 8 (1674 views)
Re: [amy_amy] help with create object [In reply to] Can't Post

First don't name your packages starting with a lowercase letter (unless they are pragma-like).

Your problem is probably that there exists a module called 'Test' and you have a case-insensitive filesystem.


KevinR
Veteran


Jun 11, 2006, 7:01 PM

Post #3 of 8 (1672 views)
Re: [amy_amy] help with create object [In reply to] Can't Post

#!/usr/bin/perl -w
#usetest.pl

use strict;
use test; <-- this must be named test.pm to work like this and the module must be in the cgi-bin or stored in one of the @INC directories
-------------------------------------------------


amy_amy
Novice

Jun 11, 2006, 7:05 PM

Post #4 of 8 (1671 views)
Re: [KevinR] help with create object [In reply to] Can't Post

mjgray06 and KevinR,

Thank you very much for your help.


davorg
Thaumaturge / Moderator

Jun 12, 2006, 5:35 AM

Post #5 of 8 (1664 views)
Re: [KevinR] help with create object [In reply to] Can't Post


In Reply To

Code
use test;  <-- this must be named test.pm to work like this and the module must be in the cgi-bin or stored in one of the @INC directories



The original question gave no indication that this is a CGI question - so it's probably best not to make any assumptions.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


KevinR
Veteran


Jun 12, 2006, 10:06 AM

Post #6 of 8 (1660 views)
Re: [davorg] help with create object [In reply to] Can't Post

yes, good observation. I did assume. Blush
-------------------------------------------------


amy_amy
Novice

Jun 14, 2006, 6:15 AM

Post #7 of 8 (1649 views)
Re: [KevinR] help with create object [In reply to] Can't Post

What is difference of .pm, .pl and .plx?



Thanks,


davorg
Thaumaturge / Moderator

Jun 15, 2006, 7:34 AM

Post #8 of 8 (1645 views)
Re: [amy_amy] help with create object [In reply to] Can't Post

(If you have a new question, then please start a new discussion thread)

.pm is a Perl module - a library of Perl routines.

.pl is a Perl library - this dates from pre-Perl 5 days when modules didn't exit. It's usually a file that contains a number of subroutines which is included with "require" or "do". No-one writes libraries like this any more; we use modules instead. These days people often use .pl to designate a Perl program.

.plx is a "Perl executable" - this is (rarely) used to designate a Perl program.

The only one of these which is required is .pm. Perl specifically looks for .pm files when you "use" a module. It's unnecessary to use .pl or .plx to designate a Perl program unless you're stuck on a crippled system like Windows which associated programs with files using their extension.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives