Click to See Complete Forum and Search --> : perl: module weirdness


YaRness
12-07-2000, 07:48 PM
i have these two files:

(as always, forgive me for working in winderz, at work it's more convenient unfortunately, but i shall work in linux again soon enough after i get my box back up. just not tonight.)

c:\scripts\test.pl

#!c:\perl\bin\perl.pl

use strict;

use range;

$myyar= range->new();
$myyar->rangelist(2);
my $myrange = $myyar->rangelist;
print "\$myrange $myrange\n";



c:\perl\lib\range.pm

#!c:\perl\bin\perl.exe -w

package range;

use strict;
use warnings;

sub new
{
my $self = {};
$self->{RANGELIST} = undef;
bless($self);
return $self;
}

sub rangelist
{
my $self = shift;
if (@_) {$self->{RANGELIST} = shift;}
return $self->{RANGELIST};
}

1;


nothing fancy, and it works fine. my question is, if i had range.pm in my c:\scripts directory, what would i have to change in either file to make it work the same. i was having problems getting it to work like that earlier. obviously it'd be better to keep pm files in a standard place, i'm just mostly curious as to what i was doing wrong. i think at one point i had the line in test.pl as "::scripts::range", but it returned the error "Can't call method "import" without a package or object reference at test.pl line 5." and i couldn't figure out what the fsck that meant.


------------------
"Assembly of Japanese bicycle require great peace of mind."
Registered Linux User #188285 http://counter.li.org/
------------------

klamath
12-08-2000, 12:18 AM
For one thing, Perl modules should start with an uppercase letter (unless it's a pragma, which this is not).

Perl looks for modules in the @INC array. To manipulate it, try 'use lib qw(dir1 dir2 dir3);'. So for example:

use lib qw(c:/scripts/ );

------------------
- Klamath
Get my GnuPG Key Here (http://klamath.dyndns.org/mykey.asc)
Looking for an open source project to contribute to? Check out the Better Bulletin Board (http://bbb.sourceforge.net)

TheLinuxDuck
12-08-2000, 10:59 AM
Originally posted by klamath:
For one thing, Perl modules should start with an uppercase letter (unless it's a pragma, which this is not).

The only language that I know of that has strict requirements for variable/sub naming is Java.

Upper/lower case naming is totally up to the author. I personally only use uppercase letters on file handles. I don't like uppercase letters in variables/subs.

IMHO, if the reader of the code cannot distiguish between rangeofvalues and rangeofvalor, then they need to not be coding.

But, I also can't stand it when people use tabs for block formatting. So, to each his own. http://www.linuxnewbie.org/ubb/smile.gif

------------------
TheLinuxDuck
Wait... that's a penguin?!?!?
:wq

YaRness
12-08-2000, 11:34 AM
i think he was referring to something like the perlstyle faq. sometimes some kinda consistency between different programmers can make things easier.

then again, if it's hard to write, maybe it should be hard to read. job security and all that.

i set my tabs to do 4 spaces, that's about all the comforming i've done so far. plus when you use 8 (default in a lot of proggies i think), embedded loops start to run off the screen too soon.

------------------
"Assembly of Japanese bicycle require great peace of mind."
Registered Linux User #188285 http://counter.li.org/
------------------

klamath
12-08-2000, 02:01 PM
The only language that I know of that has strict requirements for variable/sub naming is Java.

Upper/lower case naming is totally up to the author.


Yeah, obviously - Perl mandates that TMTOWTDI. It's just that the informal standard is for module names starting with a capital letter. Think of every single module included with Perl, or on CPAN (that I know of) -- the name starts with a capital letter. Consider: DBI, Apache, Carp, Benchmark, English, Safe, Socket, etc. On the other hand, those modules which actually modify Perl's behavior are in lower-case: strict, constant, lib, diagnostics, locale, overload, etc.

------------------
- Klamath
Get my GnuPG Key Here (http://klamath.dyndns.org/mykey.asc)
Looking for an open source project to contribute to? Check out the Better Bulletin Board (http://bbb.sourceforge.net)

TheLinuxDuck
12-08-2000, 03:42 PM
Originally posted by klamath:
Consider: DBI, Apache, Carp, Benchmark, English, Safe, Socket, etc. On the other hand, those modules which actually modify Perl's behavior are in lower-case: strict, constant, lib, diagnostics, locale, overload, etc.

I see your point... I guess I'd never really noticed or paid any attention to the module names vs pragma names.

------------------
TheLinuxDuck
Wait... that's a penguin?!?!?
:wq

YaRness
12-08-2000, 04:21 PM
err, not perlstyle faq. do a "man perlstyle"

------------------
"Assembly of Japanese bicycle require great peace of mind."
Registered Linux User #188285 http://counter.li.org/
------------------