Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use || not or! :-) #10781

Closed
p5pRT opened this issue Oct 29, 2010 · 10 comments
Closed

use || not or! :-) #10781

p5pRT opened this issue Oct 29, 2010 · 10 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 29, 2010

Migrated from rt.perl.org#78708 (status was 'resolved')

Searchable as RT78708$

@p5pRT
Copy link
Author

p5pRT commented Oct 29, 2010

From alex.davies@talktalk.net

Created by alex@Amelie

Spotted the following (likely) misuses of C<or>​:

:​: cpan\Archive-Tar\lib\Archive\Tar.pm
**** (1645) sub iter {
1648​: my $compressed = shift or 0;

:​: cpan\Module-Load-Conditional\lib\Module\Load\Conditional.pm
**** (328) sub _parse_version {
331​: my $verbose = shift or 0;

:​: utils\h2xs.PL
**** (515) sub usage {
896​: my $SEEK_SET = eval 'use Fcntl qw/SEEK_SET/; SEEK_SET' or 0;

The C<or>s should be C<||>s.

[I was surprised that this usage didn't generate a warning; but

% perl -we "my $x = undef or 0;"

...remains silent]

Perl Info

Flags:
    category=core
    severity=low

This perlbug was built using Perl 5.10.0 - Mon Aug 11 04:41:10 2008
It is being executed now by  Perl 5.13.5 - Thu Oct  7 18:04:46 2010.

Site configuration information for perl 5.13.5:

Configured by alex at Thu Oct  7 18:04:46 2010.

Summary of my perl5 (revision 5 version 13 subversion 5) configuration:
  Commit id: f61b60f11869c5ab510b94d1b8fc16df4be9be36
  Platform:
    osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags 
='-nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT  -DPERL_IMPLICIT_CONTEXT 
 -DPERL_IMPLICIT_SYS -DUSE_PERLIO -D_USE_32BIT_TIME_T -DPERL_MSVCRT_READFIX',
    optimize='-MD -Zi -DNDEBUG -O1',
    cppflags='-DWIN32'
    ccversion='12.00.8804', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags 
'-nologo -nodefaultlib -debug -opt:ref,icf  -libpath:"c:\perl\lib\CORE"  -machine:x86'
    libpth=C:\PROGRA~1\MICROS~4\VC98\lib
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib 
shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib 
odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib 
advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib 
version.lib odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl513.lib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', 
ddlflags='-dll -nologo -nodefaultlib -debug -opt:ref,icf  -libpath:"c:\perl\lib\CORE"  -machine:x86'

Locally applied patches:



@INC for perl 5.13.5:
    C:/alex/src/perl/blead/perl/lib
    .


Environment for perl 5.13.5:
    HOME=C:\alex
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\alex\bin;C:\Program 
Files\Microsoft SDK\Bin\.;C:\Program Files\Microsoft 
SDK\Bin\WinNT\.;C:\strawberry\perl\bin;C:\Program Files\Tcl-8.5.0\bin;C:\PerlAPPv9\bin;C:\Program 
Files\QuickTime\QTSystem\;C:\strawberry\c\bin;C:\Program Files\Git\cmd;C:\Program Files\Microsoft 
Visual Studio\VC98\Bin;C:\Program Files\Microsoft SDK\Bin\.;C:\Program Files\Microsoft 
SDK\Bin\WinNT;C:\cygwin\bin
    PERL_BADLANG (unset)
    SHELL (unset)



@p5pRT
Copy link
Author

p5pRT commented Oct 30, 2010

From @ikegami

Thanks for the report. One catch​: bugs for modules in cpan/ should be
submitted to the module's bug tracker.

[I was surprised that this usage didn't generate a warning

0 and 1 don't generate warnings for being used in void context.

perl -we"0"

perl -we"1"

perl -we"2"
Useless use of a constant (2) in void context at -e line 1.

@p5pRT
Copy link
Author

p5pRT commented Oct 30, 2010

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Dec 5, 2011

From @chorny

On Fri Oct 29 10​:52​:14 2010, alex.davies@​talktalk.net wrote​:

:​: cpan\Archive-Tar\lib\Archive\Tar.pm
:​: cpan\Module-Load-Conditional\lib\Module\Load\Conditional.pm

Submitted patches to corresponding repositories.

:​: utils\h2xs.PL

Patch attached.

--
Alexandr Ciornii, http​://chorny.net

@p5pRT
Copy link
Author

p5pRT commented Dec 5, 2011

From @chorny

0001-instead-of-or-perl-78708.patch
From 4cfc00f98b1d7921629fe7d00c9519885f018f06 Mon Sep 17 00:00:00 2001
From: Alexandr Ciornii <alexchorny@gmail.com>
Date: Wed, 7 Sep 2011 00:30:46 +0300
Subject: [PATCH] || instead of "or" (perl#78708)

---
 utils/h2xs.PL |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/utils/h2xs.PL b/utils/h2xs.PL
index 634e891..90d8ece 100644
--- a/utils/h2xs.PL
+++ b/utils/h2xs.PL
@@ -893,7 +893,7 @@ if( @path_h ){
       }
       else {
 	# Work from miniperl too - on "normal" systems
-        my $SEEK_SET = eval 'use Fcntl qw/SEEK_SET/; SEEK_SET' or 0;
+        my $SEEK_SET = eval 'use Fcntl qw/SEEK_SET/; SEEK_SET' || 0;
         seek CH, 0, $SEEK_SET;
         my $src = do { local $/; <CH> };
         close CH;
-- 
1.7.6.msysgit.0

@p5pRT
Copy link
Author

p5pRT commented Dec 5, 2011

From @hvds

"Alexandr Ciornii via RT" <perlbug-followup@​perl.org> wrote​:
:index 634e891..90d8ece 100644
:--- a/utils/h2xs.PL
:+++ b/utils/h2xs.PL
:@​@​ -893,7 +893,7 @​@​ if( @​path_h ){
: }
: else {
: # Work from miniperl too - on "normal" systems
:- my $SEEK_SET = eval 'use Fcntl qw/SEEK_SET/; SEEK_SET' or 0;
:+ my $SEEK_SET = eval 'use Fcntl qw/SEEK_SET/; SEEK_SET' || 0;
: seek CH, 0, $SEEK_SET;
: my $src = do { local $/; <CH> };
: close CH;

Um, that's wrong too. You'll need parens.

Hugo

@p5pRT
Copy link
Author

p5pRT commented Dec 5, 2011

From @tamias

On Mon, Dec 05, 2011 at 07​:59​:27AM +0000, hv@​crypt.org wrote​:

"Alexandr Ciornii via RT" <perlbug-followup@​perl.org> wrote​:
:index 634e891..90d8ece 100644
:--- a/utils/h2xs.PL
:+++ b/utils/h2xs.PL
:@​@​ -893,7 +893,7 @​@​ if( @​path_h ){
: }
: else {
: # Work from miniperl too - on "normal" systems
:- my $SEEK_SET = eval 'use Fcntl qw/SEEK_SET/; SEEK_SET' or 0;
:+ my $SEEK_SET = eval 'use Fcntl qw/SEEK_SET/; SEEK_SET' || 0;
: seek CH, 0, $SEEK_SET;
: my $src = do { local $/; <CH> };
: close CH;

Um, that's wrong too. You'll need parens.

It appears to parse as desired without the parens​:

% perl -MO=Deparse,-p -e 'my $SEEK_SET = eval "use Fcntl qw/SEEK_SET/; SEEK_SET" || 0;'
(my $SEEK_SET = (eval('use Fcntl qw/SEEK_SET/; SEEK_SET') || 0));
-e syntax OK

Ronald

@p5pRT
Copy link
Author

p5pRT commented Dec 5, 2011

From @Abigail

On Mon, Dec 05, 2011 at 09​:43​:59AM -0500, Ronald J Kimball wrote​:

On Mon, Dec 05, 2011 at 07​:59​:27AM +0000, hv@​crypt.org wrote​:

"Alexandr Ciornii via RT" <perlbug-followup@​perl.org> wrote​:
:index 634e891..90d8ece 100644
:--- a/utils/h2xs.PL
:+++ b/utils/h2xs.PL
:@​@​ -893,7 +893,7 @​@​ if( @​path_h ){
: }
: else {
: # Work from miniperl too - on "normal" systems
:- my $SEEK_SET = eval 'use Fcntl qw/SEEK_SET/; SEEK_SET' or 0;
:+ my $SEEK_SET = eval 'use Fcntl qw/SEEK_SET/; SEEK_SET' || 0;
: seek CH, 0, $SEEK_SET;
: my $src = do { local $/; <CH> };
: close CH;

Um, that's wrong too. You'll need parens.

It appears to parse as desired without the parens​:

% perl -MO=Deparse,-p -e 'my $SEEK_SET = eval "use Fcntl qw/SEEK_SET/; SEEK_SET" || 0;'
(my $SEEK_SET = (eval('use Fcntl qw/SEEK_SET/; SEEK_SET') || 0));
-e syntax OK

That's because named unary operators have a higher precedence than ||.

It may not be clear to everyone that 'eval' is a named unary operator though.

Abigail

@p5pRT
Copy link
Author

p5pRT commented Dec 5, 2011

From @cpansprout

On Sun Dec 04 18​:01​:35 2011, chorny wrote​:

On Fri Oct 29 10​:52​:14 2010, alex.davies@​talktalk.net wrote​:

:​: cpan\Archive-Tar\lib\Archive\Tar.pm
:​: cpan\Module-Load-Conditional\lib\Module\Load\Conditional.pm

Submitted patches to corresponding repositories.

:​: utils\h2xs.PL

Patch attached.

Thank you. Applied as 70eec64.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Dec 5, 2011

@cpansprout - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant