BBS.ChinaUnix.net
首页 | 新闻 | Linux | FreeBSD | AIX | Windows | 博客 | 论坛 | 存储 | 网络 | 人才 | Wiki | 资料 | 读书 | 手册 | 下载 | 空间 | 搜索
  会员: 密码: 免费注册 | 忘记密码 | 会员登录 | 搜索 | 帮助 


::和->的区别
首页 » 论坛 » Perl »  
[打印] [订阅] [收藏] [本帖文本页] [推荐此主题给朋友,立即获积分]
risepp   帅哥
精灵王




UID:299421
注册:2005-8-5
最后登录: 2008-07-26
帖子:291
精华:0

可用积分:308 (白手起家)
信誉积分:100
专家积分:0 (本版:0)
空间积分:0
推广积分:0

状态:...离线...

[个人空间] [短信] [博客]


11楼 发表于 2008-5-20 18:14 
是我理解错了,export只是将该方法的包名前缀省掉了! 呵呵



您对本贴的看法:鲜花[0] 臭蛋[0]
积分兑换专区 | IT节能和TPC-E活动获奖名单 | 致电800-858-2903,了解DELL如何为你量身订制笔记本 | 送2G U盘 | 站长如何获得资金?
churchmice
风云使者
数字小白



UID:664989
注册:2008-1-23
最后登录: 2008-10-08
帖子:610
精华:0

可用积分:1279 (家境小康)
信誉积分:0
专家积分:7 (本版:7)
空间积分:0
推广积分:0

状态:...离线...

[个人空间] [短信] [博客]


12楼 发表于 2008-5-20 18:19 
回复 #10 risepp 的帖子

美女
test.pl里面少个use

use common;




您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________

其实我只是一架人肉搜索引擎
积分兑换专区 | IT节能和TPC-E活动获奖名单 | 致电800-858-2903,了解DELL如何为你量身订制笔记本 | 送2G U盘 | 站长如何获得资金?
risepp   帅哥
精灵王




UID:299421
注册:2005-8-5
最后登录: 2008-07-26
帖子:291
精华:0

可用积分:308 (白手起家)
信誉积分:100
专家积分:0 (本版:0)
空间积分:0
推广积分:0

状态:...离线...

[个人空间] [短信] [博客]


13楼 发表于 2008-5-20 18:21 
我加了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.



您对本贴的看法:鲜花[0] 臭蛋[0]
积分兑换专区 | IT节能和TPC-E活动获奖名单 | 致电800-858-2903,了解DELL如何为你量身订制笔记本 | 送2G U盘 | 站长如何获得资金?
churchmice
风云使者
数字小白



UID:664989
注册:2008-1-23
最后登录: 2008-10-08
帖子:610
精华:0

可用积分:1279 (家境小康)
信誉积分:0
专家积分:7 (本版:7)
空间积分:0
推广积分:0

状态:...离线...

[个人空间] [短信] [博客]


14楼 发表于 2008-5-20 18:35 
回复 #13 risepp 的帖子

你的代码里面

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.

[ 本帖最后由 churchmice 于 2008-5-20 18:40 编辑 ]



您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________

其实我只是一架人肉搜索引擎
积分兑换专区 | IT节能和TPC-E活动获奖名单 | 致电800-858-2903,了解DELL如何为你量身订制笔记本 | 送2G U盘 | 站长如何获得资金?
churchmice
风云使者
数字小白



UID:664989
注册:2008-1-23
最后登录: 2008-10-08
帖子:610
精华:0

可用积分:1279 (家境小康)
信誉积分:0
专家积分:7 (本版:7)
空间积分:0
推广积分:0

状态:...离线...

[个人空间] [短信] [博客]


15楼 发表于 2008-5-20 18:45 
还有这个

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.




您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________

其实我只是一架人肉搜索引擎
积分兑换专区 | IT节能和TPC-E活动获奖名单 | 致电800-858-2903,了解DELL如何为你量身订制笔记本 | 送2G U盘 | 站长如何获得资金?
risepp   帅哥
精灵王




UID:299421
注册:2005-8-5
最后登录: 2008-07-26
帖子:291
精华:0

可用积分:308 (白手起家)
信誉积分:100
专家积分:0 (本版:0)
空间积分:0
推广积分:0

状态:...离线...

[个人空间] [短信] [博客]


16楼 发表于 2008-5-20 21:12 
我看了,看来基础是关键啊,请问你这些资料是从官网文档中看的还是有电子文档啊? 能share一下么?
我最近对perl蛮感兴趣的,但是苦于没有好的资料学习!  推荐一下,这样我也可以少来烦你几次 :)



您对本贴的看法:鲜花[0] 臭蛋[0]
积分兑换专区 | IT节能和TPC-E活动获奖名单 | 致电800-858-2903,了解DELL如何为你量身订制笔记本 | 送2G U盘 | 站长如何获得资金?
risepp   帅哥
精灵王




UID:299421
注册:2005-8-5
最后登录: 2008-07-26
帖子:291
精华:0

可用积分:308 (白手起家)
信誉积分:100
专家积分:0 (本版:0)
空间积分:0
推广积分:0

状态:...离线...

[个人空间] [短信] [博客]


17楼 发表于 2008-5-20 21:20 
加了common还是不行也,报错



您对本贴的看法:鲜花[0] 臭蛋[0]
积分兑换专区 | IT节能和TPC-E活动获奖名单 | 致电800-858-2903,了解DELL如何为你量身订制笔记本 | 送2G U盘 | 站长如何获得资金?
risepp   帅哥
精灵王




UID:299421
注册:2005-8-5
最后登录: 2008-07-26
帖子:291
精华:0

可用积分:308 (白手起家)
信誉积分:100
专家积分:0 (本版:0)
空间积分:0
推广积分:0

状态:...离线...

[个人空间] [短信] [博客]


18楼 发表于 2008-5-20 21:21 
错误信息如下:
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是既有意思又复杂灵活啊   呵呵  我已经被他搞晕了!



您对本贴的看法:鲜花[0] 臭蛋[0]
积分兑换专区 | IT节能和TPC-E活动获奖名单 | 致电800-858-2903,了解DELL如何为你量身订制笔记本 | 送2G U盘 | 站长如何获得资金?
risepp   帅哥
精灵王




UID:299421
注册:2005-8-5
最后登录: 2008-07-26
帖子:291
精华:0

可用积分:308 (白手起家)
信誉积分:100
专家积分:0 (本版:0)
空间积分:0
推广积分:0

状态:...离线...

[个人空间] [短信] [博客]


19楼 发表于 2008-5-20 21:25 
误会,误会,是我搞错了,我忘了把month_days这个subroute export出来了,呵呵!  问题已经解决,非常感谢!



您对本贴的看法:鲜花[0] 臭蛋[0]
积分兑换专区 | IT节能和TPC-E活动获奖名单 | 致电800-858-2903,了解DELL如何为你量身订制笔记本 | 送2G U盘 | 站长如何获得资金?
churchmice
风云使者
数字小白



UID:664989
注册:2008-1-23
最后登录: 2008-10-08
帖子:610
精华:0

可用积分:1279 (家境小康)
信誉积分:0
专家积分:7 (本版:7)
空间积分:0
推广积分:0

状态:...离线...

[个人空间] [短信] [博客]


20楼 发表于 2008-5-20 21:25 
回复 #16 risepp 的帖子

learning perl是入门,因为是培训教材,所以要写的简单通俗易懂
intermediate perl 是将object的,讲oo proramming
接着你可以看
effective perl programming
看完之后,你再看神一样的大骆驼书
programming perl
这书涵盖了几乎一切,我现在刚看了大半,是个大坑,很容易就淹死了
看完这个,话说还有一个
perl cookbook也不错的



您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________

其实我只是一架人肉搜索引擎
积分兑换专区 | IT节能和TPC-E活动获奖名单 | 致电800-858-2903,了解DELL如何为你量身订制笔记本 | 送2G U盘 | 站长如何获得资金?

首页 » 论坛 » Perl »


 


Copyright © 2001-2008 ChinaUnix.net All Rights Reserved     联系我们:

感谢所有关心和支持过ChinaUnix的朋友们    转载本站内容请注明原作者名及出处

京ICP证041476号


清除 Cookies - ChinaUnix - Archiver - WAP - TOP

Processed in 0.083721 second(s), 4 queries , Gzip enabled