一个坑,自己掉进去好几次了。。。

35 views
Skip to first unread message

wd

unread,
Jun 28, 2012, 11:21:15 PM6/28/12
to perl...@googlegroups.com
#!/usr/bin/perl

use strict;
use warnings;

my $a;

if ( not defined $a || $a == 0 ) {
print 1;
}

就这段代码。。明眼人应该能看明白错在哪里。。。我已经掉进去好几次了。。。好像还在持续的掉。。nnd。。。

cnhack TNT

unread,
Jun 28, 2012, 11:56:13 PM6/28/12
to perl...@googlegroups.com
同掉过,路过。。。


2012/6/29 wd <w...@wdicc.com>

--
您收到此邮件是因为您订阅了 Google 网上论坛的“PerlChina Mongers 讨论组”论坛。
要向此网上论坛发帖,请发送电子邮件至 perl...@googlegroups.com
要取消订阅此网上论坛,请发送电子邮件至 perlchina+...@googlegroups.com
若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。


joe jiang

unread,
Jun 29, 2012, 1:19:39 AM6/29/12
to perl...@googlegroups.com
  DB<7> print 1 if !defined $a or $a == 0;
1


2012/6/29 cnhack TNT <cnha...@gmail.com>

Huangj

unread,
Aug 6, 2012, 9:09:49 AM8/6/12
to perl...@googlegroups.com
俺都介么写
 
my $y;
unless ( $y ) { print 1; }


要取消订阅此网上论坛,请发送电子邮件至 perlchina+unsub...@googlegroups.com

mwjp...@gmail.com

unread,
Aug 6, 2012, 11:47:30 AM8/6/12
to perl...@googlegroups.com
新手求教什麽坑?



-- Sent from my HP TouchPad

wd

unread,
Aug 6, 2012, 10:55:41 PM8/6/12
to perl...@googlegroups.com
if (not defined $a || $a == 0 )
优先级问题,本意是 ( (not defined $a) || $a == 0 ),实际是 (not ( defined $a || $a == 0 ) )

perl 里面 ! 和 not,and 和 && 优先级不一样。

2012/8/6 <mwjp...@gmail.com>:

Anthony WU

unread,
Aug 7, 2012, 7:31:23 AM8/7/12
to perl...@googlegroups.com, wd
�����@�����}
���� $a�c$b�����A�O׃��������
-------- Original Message --------
Subject: Re: [PerlChina] һ���ӣ��Լ�����ȥ�ü����ˡ�����
From: wd <w...@wdicc.com>
To: perl...@googlegroups.com
Date: 7/8/2012 10:55
> if (not defined $a || $a == 0 )
> ���ȼ����⣬������ ( (not defined $a) || $a == 0 )��ʵ���� (not ( defined $a || $a == 0 ) )
>
> perl ���� ! �� not��and �� && ���ȼ���һ��
>
> 2012/8/6 <mwjp...@gmail.com>:
>> �������ʲ���?
>>
>>
>>
>> -- Sent from my HP TouchPad
>> ________________________________
>> On 6 Aug 2012 21:09, Huangj <red...@163.com> wrote:
>> ������ôд
>>
>> my $y;
>> unless ( $y ) { print 1; }
>>
>>
>>
>> �� 2012-06-29 13:19:39��"joe jiang" <lamp...@gmail.com> ���
>>
>> DB<7> print 1 if !defined $a or $a == 0;
>> 1
>>
>>
>> 2012/6/29 cnhack TNT <cnha...@gmail.com>
>>> ͬ����·���
>>>
>>>
>>>
>>> 2012/6/29 wd <w...@wdicc.com>
>>>> #!/usr/bin/perl
>>>>
>>>> use strict;
>>>> use warnings;
>>>>
>>>> my $a;
>>>>
>>>> if ( not defined $a || $a == 0 ) {
>>>> print 1;
>>>> }
>>>>
>>>> ����δ��롣��������Ӧ���ܿ����״�������������Ѿ�����ȥ�ü����ˡ����������ڳ���ĵ�����nnd������
>>>>
>>>> --
>>>> ���յ����ʼ�����Ϊ������ Google ������̳�ġ�PerlChina Mongers �����顱��̳��
>>>> Ҫ���������̳�����뷢�͵����ʼ��� perl...@googlegroups.com��
>>>> Ҫȡ���Ĵ�������̳���뷢�͵����ʼ��� perlchina+...@googlegroups.com��
>>>> ���и�����⣬��ͨ�� http://groups.google.com/group/perlchina?hl=zh-CN ���ʴ�������̳��
>>>>
>>> --
>>> ���յ����ʼ�����Ϊ������ Google ������̳�ġ�PerlChina Mongers �����顱��̳��
>>> Ҫ���������̳�����뷢�͵����ʼ��� perl...@googlegroups.com��
>>> Ҫȡ���Ĵ�������̳���뷢�͵����ʼ��� perlchina+...@googlegroups.com��
>>> ���и�����⣬��ͨ�� http://groups.google.com/group/perlchina?hl=zh-CN ���ʴ�������̳��
>>
>> --
>> ���յ����ʼ�����Ϊ������ Google ������̳�ġ�PerlChina Mongers �����顱��̳��
>> Ҫ���������̳�����뷢�͵����ʼ��� perl...@googlegroups.com��
>> Ҫȡ���Ĵ�������̳���뷢�͵����ʼ��� perlchina+...@googlegroups.com��
>> ���и�����⣬��ͨ�� http://groups.google.com/group/perlchina?hl=zh-CN ���ʴ�������̳��
>>
>>
>>
>> --
>> ���յ����ʼ�����Ϊ������ Google ������̳�ġ�PerlChina Mongers �����顱��̳��
>> Ҫ���������̳�����뷢�͵����ʼ��� perl...@googlegroups.com��
>> Ҫȡ���Ĵ�������̳���뷢�͵����ʼ��� perlchina+...@googlegroups.com��
>> ���и�����⣬��ͨ�� http://groups.google.com/group/perlchina?hl=zh-CN ���ʴ�������̳��
>>
>> --
>> ���յ����ʼ�����Ϊ������ Google ������̳�ġ�PerlChina Mongers �����顱��̳��
>> Ҫ���������̳�����뷢�͵����ʼ��� perl...@googlegroups.com��
>> Ҫȡ���Ĵ�������̳���뷢�͵����ʼ��� perlchina+...@googlegroups.com��
>> ���и�����⣬��ͨ�� http://groups.google.com/group/perlchina?hl=zh-CN ���ʴ�������̳��

Robin Lee

unread,
Aug 7, 2012, 9:46:37 AM8/7/12
to perl...@googlegroups.com
$a $b 只在 sort 里是预设变量。在其它地方没有特别

2012/8/7 Anthony WU <anthon...@gmail.com>
不是這個問題
而是 $a與$b都是預設變量………
-------- Original Message --------
Subject: Re: [PerlChina] 一个坑,自己掉进去好几次了。。。
From: wd <w...@wdicc.com>
To: perl...@googlegroups.com
Date: 7/8/2012 10:55
> if (not defined $a || $a == 0  )
> 优先级问题,本意是 ( (not defined $a) || $a == 0  ),实际是 (not ( defined $a || $a == 0 ) )
>
> perl 里面 ! 和 not,and 和 && 优先级不一样。
>
> 2012/8/6  <mwjp...@gmail.com>:
>> 新手求教什麽坑?
>>
>>
>>
>> -- Sent from my HP TouchPad
>> ________________________________
>> On 6 Aug 2012 21:09, Huangj <red...@163.com> wrote:
>> 俺都介么写

>>
>> my $y;
>> unless ( $y ) { print 1; }
>>
>>
>>
>> 在 2012-06-29 13:19:39,"joe jiang" <lamp...@gmail.com> 写道:
>>
>>   DB<7> print 1 if !defined $a or $a == 0;
>> 1
>>
>>
>> 2012/6/29 cnhack TNT <cnha...@gmail.com>
>>> 同掉过,路过。。。

>>>
>>>
>>>
>>> 2012/6/29 wd <w...@wdicc.com>
>>>> #!/usr/bin/perl
>>>>
>>>> use strict;
>>>> use warnings;
>>>>
>>>> my $a;
>>>>
>>>> if ( not defined $a || $a == 0 ) {
>>>>    print 1;
>>>> }
>>>>

Robin Lee

unread,
Aug 7, 2012, 9:50:52 AM8/7/12
to perl...@googlegroups.com
不过,my $a 之后,一旦在它的lexical scope 里用 sort 就悲剧了。这样说来, my $a 的确是个坑

2012/8/7 Robin Lee <robinl...@gmail.com>

Hao Wu

unread,
Aug 7, 2012, 3:51:28 PM8/7/12
to perl...@googlegroups.com


A Small Aside… In Perl 6 the variables $a and $b don’t have any special global significance like they do in Perl 5. Use normal named variables ($var), positional variables ($^var) or whatever variables (*) in the sort comparison block just like any other code block.



--
Hao Wu

Lab: 334-844-2494 
Mail: 301 Funchess Hall, 
        Auburn University, 
        AL, 36849, USA

Reply all
Reply to author
Forward
0 new messages