Front page | perl.perl5.porters |
Postings from June 2008
[perl #56416] Odd behavior of given {when (... or ...) ...}
From:
perlbug-followup
Date:
June 27, 2008 07:23
Subject:
[perl #56416] Odd behavior of given {when (... or ...) ...}
Message ID:
rt-3.6.HEAD-18542-1214572151-1072.56416-75-0@perl.org
# New Ticket Created by spamdummy3@yahoo.com
# Please include the string: [perl #56416]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=56416 >
This is a bug report for perl from spamdummy3@yahoo.com,
generated with the help of perlbug 1.36 running under perl 5.10.0.
-----------------------------------------------------------------
"perlsyn" says that in the "when" clause of a "given" block, "or"
should cause the test to be applied recursively to the first
argument. I can't fathom why the recursive magic is supposed to
apply to only the first argument, even if it evaluates as false,
but as implemented, "or" in a "given" appears to work neither as
documented nor as to how I think it ought to work. This code:
sub test
{my $x = shift;
given ($x)
{when ('a' or 'b') {say 'Y';}
default {say 'N';}}
given ($x)
{when ('a' or $_ ~~ 'b') {say 'Y';}
default {say 'N';}}
given ($x)
{when ($_ ~~ 'a' or 'b') {say 'Y';}
default {say 'N';}}}
test('a');
test('b');
ought, I think, to print six "Y"s, but instead it prints:
Y
Y
Y
N
N
Y
I asked about this weirdness on Perl Monks
(http://perlmonks.org/?node_id=693370), but no one was able to
explain it, so I think it's a bug.
-----------------------------------------------------------------
---
Flags:
category=core
severity=medium
---
This perlbug was built using Perl 5.10.0 - Sat Jun 7 17:43:34 EDT 2008
It is being executed now by Perl 5.10.0 - Sat Jun 7 13:10:17 EDT 2008.
Site configuration information for perl 5.10.0:
Configured by hippo at Sat Jun 7 13:10:17 EDT 2008.
Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
Platform:
osname=linux, osvers=2.6.24-16-generic, archname=i686-linux-thread-multi-ld
uname='linux thoth 2.6.24-16-generic #1 smp thu apr 10 13:23:42 utc 2008 i686 gnulinux '
config_args='-Dusethreads -Duselongdouble'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=define
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O3',
cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -I/usr/local/include'
ccversion='', gccversion='4.2.3 (Ubuntu 4.2.3-2ubuntu7)', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='long double', nvsize=12, Off_t='off_t', lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=/lib/libc-2.7.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.7'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fPIC', lddlflags='-shared -O3 -L/usr/local/lib'
Locally applied patches:
---
@INC for perl 5.10.0:
/usr/local/lib/perl5/5.10.0/i686-linux-thread-multi-ld
/usr/local/lib/perl5/5.10.0
/usr/local/lib/perl5/site_perl/5.10.0/i686-linux-thread-multi-ld
/usr/local/lib/perl5/site_perl/5.10.0
/usr/local/lib/perl5/site_perl
/usr/lib/perl/5.8.8
.
---
Environment for perl 5.10.0:
HOME=/home/hippo
LANG=en_US.UTF-8
LANGUAGE (unset)
LD_LIBRARY_PATH=/usr/lib/xorg
LOGDIR (unset)
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games:~/Geekdom/Perl/Code Generation:~/Geekdom/Perl/Internet:~/Geekdom/Perl/Math:~/Geekdom/Perl/Miscellany:~/Geekdom/Perl/:~/Geekdom/Perl/System Utilites:~/Geekdom/Perl/Text Processing:~/Geekdom/Perl/Typing Exercises:~/Desktop:~/Command-Line Shortcuts
PERL_BADLANG (unset)
SHELL=/bin/bash
-
[perl #56416] Odd behavior of given {when (... or ...) ...}
by perlbug-followup