::和->的区别

是我理解错了,export只是将该方法的包名前缀省掉了! 呵呵
美女
test.pl里面少个use

[Copy to clipboard] [ - ]
CODE:
use common;

我加了require common还是不行也,看来还是我哪里搞错了,而且我改为use common,也报同样的错:
Use of uninitialized value $month2 in numeric ne (!=) at /linux/src/COMMON/common.pm line 75.
Use of uninitialized value $month2 in numeric ne (!=) at /linux/src/COMMON/common.pm line 75.
Use of uninitialized value $month2 in numeric ne (!=) at /linux/src/COMMON/common.pm line 75.
你的代码里面

[Copy to clipboard] [ - ]
CODE:
my $result=internal_days("20080911","20021011");

这样写不是方法调用,而是subroutine调用
所以还是那句话,需要你自己显式指明传进去的第一个变量
只有在
$object->method()

$class->method()
的时候,perl会自动帮你补充第一个传递进去的参数(class name或者object)
其他情况均不会
从你报错的信息也可以看出说是unitialized value,你自己print下subroutine里面的@_,就会发现少传了个参数
所以问题又回到开头::和->的区别上面


希望你自己把下面这段话好好理解理解

QUOTE:
So far, we've used the method arrow syntax:
Class->method(@args);
or the equivalent:
my $beast = 'Class';
$beast->method(@args);
which constructs an argument list of:
('Class', @args)
and attempts to invoke:
Class::method('Class', @args);


my $tv_horst = Horse->new;
my $noise = $tv_horse->sound;
Now for the fun part: Perl takes the class in which the instance was blessed, in this case, Horse, and uses it to locate and invoke the method, as if we had said Horse->sound instead of $tv_horse->sound. The purpose of the original blessing is to associate a class with that reference to allow Perl to find the proper method.
In this case, Perl finds Horse::sound directly (without using inheritance), yielding the final subroutine invocation:
Horse::sound($tv_horse)
Note that the first parameter here is still the instance, not the name of the class as before. neigh is the return value, which ends up as the earlier $noise variable.

还有这个

QUOTE:
We mentioned that there are two styles of method invocation. The first style for invoking a method looks like this:

INVOCANT->METHOD(LIST)
INVOCANT->METHOD


For obvious reasons, this style is usually called the arrow form of invocation. (Do not confuse -> with =>, the "double-barreled" arrow used as a fancy comma.) Parentheses are required if there are any arguments. When executed, the invocation first locates the subroutine determined jointly by the class of the INVOCANT and the METHOD name, and then calls that subroutine, passing INVOCANT as its first argument.

我看了,看来基础是关键啊,请问你这些资料是从官网文档中看的还是有电子文档啊? 能share一下么?
我最近对perl蛮感兴趣的,但是苦于没有好的资料学习!  推荐一下,这样我也可以少来烦你几次 :)
加了common还是不行也,报错
错误信息如下:
Undefined subroutine &main::month_days called at ./test line 17.

感觉好像是没有export出来唷。

这是我在common中写得代码。

use strict;
package common;

use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(internal_days);


perl是既有意思又复杂灵活啊   呵呵  我已经被他搞晕了!
误会,误会,是我搞错了,我忘了把month_days这个subroute export出来了,呵呵!  问题已经解决,非常感谢!
learning perl是入门,因为是培训教材,所以要写的简单通俗易懂
intermediate perl 是将object的,讲oo proramming
接着你可以看
effective perl programming
看完之后,你再看神一样的大骆驼书
programming perl
这书涵盖了几乎一切,我现在刚看了大半,是个大坑,很容易就淹死了
看完这个,话说还有一个
perl cookbook也不错的