develooper Front page | perl.perl5.porters | Postings from March 2007

[perl #42168] Possible bug in logical OR

Thread Next
karl-boyken @ uiowa . edu
March 29, 2007 23:58
[perl #42168] Possible bug in logical OR
Message ID:
# New Ticket Created by 
# Please include the string:  [perl #42168]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.35 running under perl v5.8.5.

The logical or operators '||' and 'or' do not behave identically when used
between an assignment statement and the 'last' operator.  In the example
program, below, the following lines do not behave identically when 'or' is
changed to '||':

  my($resp) = $results->control( LDAP_CONTROL_PAGED ) or last;
  $cookie = $resp->cookie or last;

When 'or' is used, the program functions as expected, with no errors or
warnings.  When '||' is used, the program terminates with the following error

Can't call method "cookie" without a package or object reference at ./foo4 line 62, <DATA> line 403.

I the assignment to $resp is wrapped in parantheses, the program behaves

  (my($resp) = $results->control( LDAP_CONTROL_PAGED )) || last;
  $cookie = $resp->cookie or last;

I've appended the example program.  I've tried the program on the following
platforms, with identical results:

  Perl 5.8.8, built from source on RedHat Linux AS release 4
  Perl 5.8.3, built from source on HP-UX 11.23

Karl Boyken, system administrator
Department of Computer Science, The University of Iowa
Iowa City, IA 52242

Example program:

#!/local/pkg/perl/=/bin/perl -w

use strict;

use English;
use Net::LDAP;
use Net::LDAP::Control::Paged;
use Net::LDAP::Constant qw( LDAP_CONTROL_PAGED ); 

my($ad) = Net::LDAP->new(
                         port => 389,
                         version => 3
my($connect_error) = $EVAL_ERROR;
if ($connect_error || (! defined($ad))) {
  die "new failed:  " . $connect_error . "\n";

my($mesg) = $ad->start_tls(
                           verify => 'require',
                           sslversion => 'tlsv1',
                           cafile => '/etc/openldap/cacerts/csgadcert.pem'
if ($mesg->code()) {
  die "start_tls failed:  " . $mesg->code() . "\n";

$mesg = $ad->bind(
                  password =>'********';
if ( $mesg->code) {
  die("ADS is_user:  bind failed\n");

my($searchbase) = "OU=people,DC=divms,DC=uiowa,DC=edu";
my($filter) = "sAMAccountname=*";
my($attrs) = 'sAMAccountname';

my($page) = Net::LDAP::Control::Paged->new( size => 400 );
my($cookie) = "";
my($sam) = "";
my($attr) = "";
my($entry) = "";

while (1) {
  my($results) = $ad->search(
                             base    => $searchbase,
                             filter  => $filter,
                             attrs   => [$attrs],
                             control => $page,
  foreach $entry ($results->all_entries()) {
    foreach $attr ($entry->attributes()) {
      $sam = $entry->get_value($attr);
      print "$sam\n";
#  my($resp) = $results->control( LDAP_CONTROL_PAGED ) or last;
  my($resp) = $results->control( LDAP_CONTROL_PAGED ) || last;
  $cookie = $resp->cookie or last;

if ($cookie) {
  my($mesg) = $ad->search(
                          base    => $searchbase,
                          filter  => $filter,
                          attrs   => [$attrs],
                          control => $page,
  foreach $entry ($mesg->all_entries()) {
    foreach $attr ($entry->attributes()) {
      $sam = $entry->get_value($attr);
      print "$sam\n";

This perlbug was built using Perl v5.8.5 in the Red Hat build system.
It is being executed now by Perl v5.8.5 - Mon Jul 24 18:27:33 EDT 2006.

Site configuration information for perl v5.8.5:

Configured by Red Hat, Inc. at Mon Jul 24 18:27:33 EDT 2006.

Summary of my perl5 (revision 5 version 8 subversion 5) configuration:
    osname=linux, osvers=2.6.9-22.18.bz155725.elsmp, archname=x86_64-linux-thread-multi
    uname='linux 2.6.9-22.18.bz155725.elsmp #1 smp thu nov 17 15:34:08 est 2005 x86_64 x86_64 x86_64 gnulinux '
    config_args='-des -Doptimize=-O2 -g -pipe -m64 -Dversion=5.8.5 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Dlibpth=/usr/local/lib64 /lib64 /usr/lib64 -Dprivlib=/usr/lib/perl5/5.8.5 -Dsitelib=/usr/lib/perl5/site_perl/5.8.5 -Dvendorlib=/usr/lib/perl5/vendor_perl/5.8.5 -Darchlib=/usr/lib64/perl5/5.8.5/x86_64-linux-thread-multi -Dsitearch=/usr/lib64/perl5/site_perl/5.8.5/x86_64-linux-thread-multi -Dvendorarch=/usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi -Darchname=x86_64-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dinc_version_list=5.8.4 5.8.3 5.8.2 5.8.1 5.8.0'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=define uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2 -g -pipe -m64',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='3.4.6 20060404 (Red Hat 3.4.6-2)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =''
    libpth=/usr/local/lib64 /lib64 /usr/lib64
    libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/, so=so, useshrplib=true,
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib64/perl5/5.8.5/x86_64-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared'

Locally applied patches:

@INC for perl v5.8.5:

Environment for perl v5.8.5:
    LANGUAGE (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About