use strict ;
use warnings ;
open(my $h, "<test.dat");
my %h ; 就行了,
$h{name} = "test.dat";
不要紧,讨论问题么,吵架也正常,
2010/8/9 snyh <[email protected]>
> 这个方式 是我错了。没测试就说了 没注意到申明问题
> 以前都是对 "对象" 上面添加额外信息 想当然认为glob会自动转换。
>
> 影响您心情 对不住了
> 我不该说那么多废话
>
> 在 2010年8月9日 下午1:28,Michael Zeng <[email protected]> 写道:
> > 咱就讨论个问题, 你哪来那么多话
> >
> > 就算你是绝顶高手, 也不能不允许别人鄙视吧,呵呵
> >
> > 你的代码:
> >
> > use strict ;
> > use warnings ;
> >
> >
> > open(my $h, "<test.dat");
> > $h{name} = "test.dat";
> > 有编译error,
> >
> > 你不会 不加 use strict /warnings 吧, 服了你了
> >
> >
> >
> > 2010/8/9 snyh <[email protected]>
> >>
> >> 把文件名存在文件句柄里面, 这样也是一一对应,并且存取的代价都可忽略不计,
> >> 我当然知道您会, 只是这个方式您的语气似乎有些鄙视?
> >> 这样也许会隐藏其他我没有想到的问题, 反正为以前写perl-gtk的时候,都是把数据存在object里面,不使用GTK本身的user_data
> >>
> >> 如果不是使用filehandle 模块, 文件句柄是一个glob,
> >> 你直接把它当作hash使用也行,自动创建了一个哈希(我想内存方面的问题,如果用perl,这点消耗完全没必要考虑)
> >>
> >> 我觉得有问题是,
> >> "就是 我要打开的文件太多
> >> 很多 file handle ,
> >> 要回到很前面 才查到 打开哪个文件,如果 能从 handle直接 知道 就好了"
> >> 既然 你能"回到很前面"(我想的是,前面代表代码前面)查到那个是那个文件。
> >> 那你不知道那个handle是那个文件, 是不是你自己的代码组织有问题?
> >> 文件再多能有多少? 不可能您的程序是万能程序,需要处理世界上所有的事情吧?
> >> 程序只是关注一定范围的事情, 哪个filehandle对应那个文件你自己都搞不清楚(或者说整理不清楚)你如何组织程序的主要逻辑?
> >>
> >> 我阅历有限,暂时能想到的只有一种情况,需要通过句柄知道文件名
> >> --- 代码不是你一个人写的,在团队中,
> 需要调用其他人的代码,所有不知道对应文件名很正常。不过调研代码都到了文件句柄这个层次,也有点太紧耦合了吧?
> >>
> >> 在 2010年8月9日 上午6:44,Michael Zeng <[email protected]> 写道:
> >> > 有啥问题
> >> >
> >> >
> >> > 你这创建了 %h , 啊, 我也会啊
> >> >
> >> > 2010/8/8 snyh <[email protected]>
> >> >>
> >> >> open(my $h, "<test.dat");
> >> >> $h{name} = "test.dat";
> >> >>
> >> >> 打开文件时,把文件名存在filehandle里面 也许比较适合
> >> >>
> >> >> 不过你这个需求,貌似有问题。。。
> >> >> 在 2010年8月8日 上午7:44,Michael Zeng <[email protected]> 写道:
> >> >> > 就是 我要打开的文件太多
> >> >> >
> >> >> > 很多 file handle ,
> >> >> >
> >> >> > 要回到很前面 才查到 打开哪个文件,如果 能从 handle直接 知道 就好了
> >> >> >
> >> >> >
> >> >> >
> >> >> > 2010/8/8 Huangj <[email protected]>
> >> >> >>
> >> >> >> 介个需求是如何产生的?
> >> >> >>
> >> >> >> At 2010-08-05 22:30:08,"Michael Zeng" <[email protected]>
> wrote:
> >> >> >>
> >> >> >> 就是
> >> >> >>
> >> >> >> open my $F1, '<', 'ABC'
> >> >> >>
> >> >> >> or open my $F2 , '>' , "DEF" ;
> >> >> >>
> >> >> >>
> >> >> >> 现在 拿到 $F1, $F2 , 如何返回文件的名称呢
> >> >> >>
> >> >> >> 比如ABC , DEF
> >> >> >>
> >> >> >>
> >> >> >>
> >> >> >> --
> >> >> >> Yours Sincerely
> >> >> >> Zeng Hong
> >> >> >>
> >> >> >> --
> >> >> >> 您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。
> >> >> >> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。
> >> >> >> 要取消订阅此网上论坛,请发送电子邮件至
> >> >> >> [email protected]<perlchina%[email protected]>
> 。
> >> >> >> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN
> >> >> >> 访问此网上论坛。
> >> >> >>
> >> >> >>
> >> >> >> ________________________________
> >> >> >> 您想拥有和网易免费邮箱一样强大的软件吗?
> >> >> >>
> >> >> >> --
> >> >> >> 您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。
> >> >> >> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。
> >> >> >> 要取消订阅此网上论坛,请发送电子邮件至
> >> >> >> [email protected]<perlchina%[email protected]>
> 。
> >> >> >> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN
> >> >> >> 访问此网上论坛。
> >> >> >
> >> >> >
> >> >> >
> >> >> > --
> >> >> > Yours Sincerely
> >> >> > Zeng Hong
> >> >> >
> >> >> > --
> >> >> > 您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。
> >> >> > 要向此网上论坛发帖,请发送电子邮件至 [email protected]。
> >> >> > 要取消订阅此网上论坛,请发送电子邮件至
> >> >> > [email protected]<perlchina%[email protected]>
> 。
> >> >> > 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN访问此网上论坛。
> >> >> >
> >> >>
> >> >> --
> >> >> 您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。
> >> >> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。
> >> >> 要取消订阅此网上论坛,请发送电子邮件至
> >> >> [email protected]<perlchina%[email protected]>
> 。
> >> >> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN访问此网上论坛。
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > Yours Sincerely
> >> > Zeng Hong
> >> >
> >> > --
> >> > 您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。
> >> > 要向此网上论坛发帖,请发送电子邮件至 [email protected]。
> >> > 要取消订阅此网上论坛,请发送电子邮件至
> >> > [email protected]<perlchina%[email protected]>
> 。
> >> > 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。
> >> >
> >>
> >> --
> >> 您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。
> >> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。
> >> 要取消订阅此网上论坛,请发送电子邮件至
> >> [email protected]<perlchina%[email protected]>
> 。
> >> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。
> >>
> >
> >
> >
> > --
> > Yours Sincerely
> > Zeng Hong
> >
> > --
> > 您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。
> > 要向此网上论坛发帖,请发送电子邮件至 [email protected]。
> > 要取消订阅此网上论坛,请发送电子邮件至
> > [email protected]<perlchina%[email protected]>
> 。
> > 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。
> >
>
> --
> 您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。
> 要向此网上论坛发帖,请发送电子邮件至 [email protected]。
> 要取消订阅此网上论坛,请发送电子邮件至
> [email protected]<perlchina%[email protected]>
> 。
> 若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。
>
>
--
Yours Sincerely
Zeng Hong
--
您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。
要向此网上论坛发帖,请发送电子邮件至 [email protected]。
要取消订阅此网上论坛,请发送电子邮件至 [email protected]。
若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。