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

Silently ignores commonly-misspelled PERL5OPTS environment variable #16757

Closed
p5pRT opened this issue Nov 19, 2018 · 14 comments
Closed

Silently ignores commonly-misspelled PERL5OPTS environment variable #16757

p5pRT opened this issue Nov 19, 2018 · 14 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 19, 2018

Migrated from rt.perl.org#133669 (status was 'open')

Searchable as RT133669$

@p5pRT
Copy link
Author

p5pRT commented Nov 19, 2018

From @leonerd

Created by leo@shy.leo

I often forget the name of the variable and get confused when (e.g.)

  $ PERL5OPTS=-MDevel​::Cover prove -r

doesn't work. The variable name I wanted was PERL5OPT.

I wonder if core could add a little

if(getenv("PERL5OPTS"))
  warn("PERL5OPTS is set; did you mean to set PERL5OPT instead?");

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.26.2:

Configured by Debian at Wed Oct 10 09:30:31 UTC 2018.

Summary of my perl5 (revision 5 version 26 subversion 2) configuration:
   
  Platform:
    osname=linux
    osvers=4.9.0
    archname=x86_64-linux-gnu-thread-multi
    uname='linux localhost 4.9.0 #1 smp debian 4.9.0 x86_64 gnulinux '
    config_args='-Dusethreads -Duselargefiles -Dcc=x86_64-linux-gnu-gcc -Dcpp=x86_64-linux-gnu-cpp -Dld=x86_64-linux-gnu-gcc -Dccflags=-DDEBIAN -Wdate-time -D_FORTIFY_SOURCE=2 -g -O2 -fdebug-prefix-map=/build/perl-vGKoLJ/perl-5.26.2=. -fstack-protector-strong -Wformat -Werror=format-security -Dldflags= -Wl,-z,relro -Dlddlflags=-shared -Wl,-z,relro -Dcccdlflags=-fPIC -Darchname=x86_64-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.26 -Darchlib=/usr/lib/x86_64-linux-gnu/perl/5.26 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/x86_64-linux-gnu/perl5/5.26 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.26.2 -Dsitearch=/usr/local/lib/x86_64-linux-gnu/perl/5.26.2 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Duse64bitint -Dman1ext=1 -Dman3ext=3perl
-Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -Ui_libutil -Ui_xlocale -Uversiononly -DDEBUGGING=-g -Doptimize=-O2 -dEs -Duseshrplib -Dlibperl=libperl.so.5.26.2'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='x86_64-linux-gnu-gcc'
    ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    optimize='-O2 -g'
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion=''
    gccversion='8.2.0'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='x86_64-linux-gnu-gcc'
    ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/8/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
    libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
    perllibs=-ldl -lm -lpthread -lc -lcrypt
    libc=libc-2.27.so
    so=so
    useshrplib=true
    libperl=libperl.so.5.26
    gnulibc_version='2.27'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -L/usr/local/lib -fstack-protector-strong'

Locally applied patches:
    DEBPKG:debian/cpan_definstalldirs - Provide a sensible INSTALLDIRS default for modules installed from CPAN.
    DEBPKG:debian/db_file_ver - https://bugs.debian.org/340047 Remove overly restrictive DB_File version check.
    DEBPKG:debian/doc_info - Replace generic man(1) instructions with Debian-specific information.
    DEBPKG:debian/enc2xs_inc - https://bugs.debian.org/290336 Tweak enc2xs to follow symlinks and ignore missing @INC directories.
    DEBPKG:debian/errno_ver - https://bugs.debian.org/343351 Remove Errno version check due to upgrade problems with long-running processes.
    DEBPKG:debian/libperl_embed_doc - https://bugs.debian.org/186778 Note that libperl-dev package is required for embedded linking
    DEBPKG:fixes/respect_umask - Respect umask during installation
    DEBPKG:debian/writable_site_dirs - Set umask approproately for site install directories
    DEBPKG:debian/extutils_set_libperl_path - EU:MM: set location of libperl.a under /usr/lib
    DEBPKG:debian/no_packlist_perllocal - Don't install .packlist or perllocal.pod for perl or vendor
    DEBPKG:debian/fakeroot - Postpone LD_LIBRARY_PATH evaluation to the binary targets.
    DEBPKG:debian/instmodsh_doc - Debian policy doesn't install .packlist files for core or vendor.
    DEBPKG:debian/ld_run_path - Remove standard libs from LD_RUN_PATH as per Debian policy.
    DEBPKG:debian/libnet_config_path - Set location of libnet.cfg to /etc/perl/Net as /usr may not be writable.
    DEBPKG:debian/perlivp - https://bugs.debian.org/510895 Make perlivp skip include directories in /usr/local
    DEBPKG:debian/deprecate-with-apt - https://bugs.debian.org/747628 Point users to Debian packages of deprecated core modules
    DEBPKG:debian/squelch-locale-warnings - https://bugs.debian.org/508764 Squelch locale warnings in Debian package maintainer scripts
    DEBPKG:debian/patchlevel - https://bugs.debian.org/567489 List packaged patches for 5.26.2-7+b1 in patchlevel.h
    DEBPKG:fixes/document_makemaker_ccflags - https://bugs.debian.org/628522 [rt.cpan.org #68613] Document that CCFLAGS should include $Config{ccflags}
    DEBPKG:debian/find_html2text - https://bugs.debian.org/640479 Configure CPAN::Distribution with correct name of html2text
    DEBPKG:debian/perl5db-x-terminal-emulator.patch - https://bugs.debian.org/668490 Invoke x-terminal-emulator rather than xterm in perl5db.pl
    DEBPKG:debian/cpan-missing-site-dirs - https://bugs.debian.org/688842 Fix CPAN::FirstTime defaults with nonexisting site dirs if a parent is writable
    DEBPKG:fixes/memoize_storable_nstore - [rt.cpan.org #77790] https://bugs.debian.org/587650 Memoize::Storable: respect 'nstore' option not respected
    DEBPKG:debian/makemaker-pasthru - https://bugs.debian.org/758471 Pass LD settings through to subdirectories
    DEBPKG:debian/makemaker-manext - https://bugs.debian.org/247370 Make EU::MakeMaker honour MANnEXT settings in generated manpage headers
    DEBPKG:debian/kfreebsd-softupdates - https://bugs.debian.org/796798 Work around Debian Bug#796798
    DEBPKG:fixes/autodie-scope - https://bugs.debian.org/798096 Fix a scoping issue with "no autodie" and the "system" sub
    DEBPKG:fixes/memoize-pod - [rt.cpan.org #89441] Fix POD errors in Memoize
    DEBPKG:debian/hurd-softupdates - https://bugs.debian.org/822735 Fix t/op/stat.t failures on hurd
    DEBPKG:fixes/math_complex_doc_great_circle - https://bugs.debian.org/697567 [rt.cpan.org #114104] Math::Trig: clarify definition of great_circle_midpoint
    DEBPKG:fixes/math_complex_doc_see_also - https://bugs.debian.org/697568 [rt.cpan.org #114105] Math::Trig: add missing SEE ALSO
    DEBPKG:fixes/math_complex_doc_angle_units - https://bugs.debian.org/731505 [rt.cpan.org #114106] Math::Trig: document angle units
    DEBPKG:fixes/cpan_web_link - https://bugs.debian.org/367291 CPAN: Add link to main CPAN web site
    DEBPKG:fixes/time_piece_doc - https://bugs.debian.org/817925 Time::Piece: Improve documentation for add_months and add_years
    DEBPKG:fixes/extutils_makemaker_reproducible - https://bugs.debian.org/835815 https://bugs.debian.org/834190 Make perllocal.pod files reproducible
    DEBPKG:fixes/file_path_hurd_errno - File-Path: Fix test failure in Hurd due to hard-coded ENOENT
    DEBPKG:debian/hppa_op_optimize_workaround - https://bugs.debian.org/838613 Temporarily lower the optimization of op.c on hppa due to gcc-6 problems
    DEBPKG:debian/installman-utf8 - https://bugs.debian.org/840211 Generate man pages with UTF-8 characters
    DEBPKG:fixes/file_path_chmod_race - https://bugs.debian.org/863870 [rt.cpan.org #121951] Prevent directory chmod race attack.
    DEBPKG:fixes/extutils_file_path_compat - Correct the order of tests of chmod(). (#294)
    DEBPKG:fixes/getopt-long-2 - [rt.cpan.org #120300] Withdraw part of commit 5d9947fb445327c7299d8beb009d609bc70066c0, which tries to implement more GNU getopt_long campatibility. GNU
    DEBPKG:fixes/getopt-long-3 - provide a default value for optional arguments
    DEBPKG:fixes/getopt-long-4 - https://bugs.debian.org/864544 [rt.cpan.org #122068] Fix issue #122068.
    DEBPKG:fixes/test-builder-reset - https://bugs.debian.org/865894 Reset inside subtest maintains parent
    DEBPKG:debian/hppa_opmini_optimize_workaround - https://bugs.debian.org/869122 Lower the optimization level of opmini.c on hppa
    DEBPKG:debian/sh4_op_optimize_workaround - https://bugs.debian.org/869373 Also lower the optimization level of op.c and opmini.c on sh4
    DEBPKG:fixes/json-pp-example - [rt.cpan.org #92793] https://bugs.debian.org/871837 fix RT-92793: bug in SYNOPSIS
    DEBPKG:debian/perldoc-pager - https://bugs.debian.org/870340 [rt.cpan.org #120229] Fix perldoc terminal escapes when sensible-pager is less
    DEBPKG:debian/prune_libs - https://bugs.debian.org/128355 Prune the list of libraries wanted to what we actually need.
    DEBPKG:fixes/rename-filexp.U-phase1 - regen-configure: rename filexp.U to filexp_path.U, phase 1
    DEBPKG:fixes/rename-filexp.U-phase2 - regen-configure: rename filexp.U to filexp_path.U, phase 2
    DEBPKG:fixes/packaging_test_skips - Skip various tests if PERL_BUILD_PACKAGING is set
    DEBPKG:debian/mod_paths - Tweak @INC ordering for Debian
    DEBPKG:fixes/encode-alias-regexp - https://bugs.debian.org/880085 fix https://github.com/dankogai/p5-encode/issues/127
    DEBPKG:fixes/CVE-2018-6797-testcase - [perl #132227] (perl #132227) restart a node if we change to uni rules within the node and encounter a sharp S
    DEBPKG:fixes/test-printf-null - https://bugs.debian.org/893601 Fix pointer to integer cast in null_printf check
    DEBPKG:debian/configure-regen - https://bugs.debian.org/762638 Regenerate Configure et al. after probe unit changes
    DEBPKG:fixes/CVE-2018-12015-Archive-Tar-directory-traversal - https://bugs.debian.org/900834 [rt.cpan.org #125523] Remove existing files before overwriting them
    DEBPKG:debian/gdbm-fatal - [perl #133295] https://bugs.debian.org/904005 Temporarily skip GDBM_File fatal.t for gdbm >= 1.15 compatibility


@INC for perl 5.26.2:
    /home/leo/lib/perl5/x86_64-linux-gnu-thread-multi
    /home/leo/lib/perl5
    /etc/perl
    /usr/local/lib/x86_64-linux-gnu/perl/5.26.2
    /usr/local/share/perl/5.26.2
    /usr/lib/x86_64-linux-gnu/perl5/5.26
    /usr/share/perl5
    /usr/lib/x86_64-linux-gnu/perl/5.26
    /usr/share/perl/5.26
    /usr/local/lib/site_perl
    /usr/local/lib/x86_64-linux-gnu/perl/5.26.0
    /usr/local/share/perl/5.26.0
    /usr/lib/x86_64-linux-gnu/perl-base


Environment for perl 5.26.2:
    HOME=/home/leo
    LANG=en_GB.UTF-8
    LANGUAGE=en_GB:en
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/leo/.npm-packages/bin:/home/leo/.cargo/bin:/home/leo/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/leo/opt/go/bin:/home/leo/src/go/bin
    PERL5LIB=/home/leo/lib/perl5
    PERL_BADLANG (unset)
    PERL_MB_OPT=--install_base=/home/leo
    PERL_MM_OPT=INSTALL_BASE=/home/leo
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Dec 6, 2018

From @jkeenan

On Mon, 19 Nov 2018 17​:07​:44 GMT, leonerd@​leonerd.org.uk wrote​:

This is a bug report for perl from leo@​shy.leo,
generated with the help of perlbug 1.40 running under perl 5.26.2.

-----------------------------------------------------------------
[Please describe your issue here]

I often forget the name of the variable and get confused when (e.g.)

$ PERL5OPTS=-MDevel​::Cover prove -r

doesn't work. The variable name I wanted was PERL5OPT.

I wonder if core could add a little

if(getenv("PERL5OPTS"))
warn("PERL5OPTS is set; did you mean to set PERL5OPT instead?");

If you could propose a patch (including a test), that would probably move discussion forward.

Thank you very much.
--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Dec 6, 2018

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

@p5pRT
Copy link
Author

p5pRT commented Dec 7, 2018

From @Tux

On Thu, 06 Dec 2018 12​:28​:04 -0800, "James E Keenan via RT" <perlbug-followup@​perl.org> wrote​:

On Mon, 19 Nov 2018 17​:07​:44 GMT, leonerd@​leonerd.org.uk wrote​:

I often forget the name of the variable and get confused when (e.g.)

$ PERL5OPTS=-MDevel​::Cover prove -r

doesn't work. The variable name I wanted was PERL5OPT.

I wonder if core could add a little

if (getenv ("PERL5OPTS"))
warn "PERL5OPTS is set; did you mean to set PERL5OPT instead?";

If you could propose a patch (including a test), that would probably
move discussion forward.

Maybe perl6 people could help/chime in

$ perl6 -e'my $perl5opt = "monkey"; say $perl5opts'
===SORRY!=== Error while compiling -e
Variable '$perl5opts' is not declared. Did you mean '$perl5opt'?
at -e​:1
------> my $perl5opt = "monkey"; say ⏏$perl5opts

So they already have the feature to do it for variables, why not
steal/borrow their logic for our environmental variables

And that could trigger someone else to do it for variables in perl5
too :)

--
H.Merijn Brand http​://tux.nl Perl Monger http​://amsterdam.pm.org/
using perl5.00307 .. 5.29 porting perl5 on HP-UX, AIX, and openSUSE
http​://mirrors.develooper.com/hpux/ http​://www.test-smoke.org/
http​://qa.perl.org http​://www.goldmark.org/jeff/stupid-disclaimers/

@p5pRT
Copy link
Author

p5pRT commented Dec 8, 2018

From @leonerd

On Thu, 06 Dec 2018 12​:28​:04 -0800
"James E Keenan via RT" <perlbug-followup@​perl.org> wrote​:

If you could propose a patch (including a test), that would probably
move discussion forward.

Thank you very much.

Attached is a patch for the code.

Unsure quite how to make an automated test for it, but in practice​:

$ PERL5OPT=-Mblib ./miniperl -e1
Can't locate blib.pm in @​INC (you may need to install the blib module)
(@​INC contains​: /home/leo/lib/perl5 .).
BEGIN failed--compilation aborted.

$ PERL5OPTS=-Mblib ./miniperl -e1
The PERL5OPTS environment variable is set - did you mean PERL5OPT
instead?

--
Paul "LeoNerd" Evans

leonerd@​leonerd.org.uk | https://metacpan.org/author/PEVANS
http​://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/

@p5pRT
Copy link
Author

p5pRT commented Dec 8, 2018

From @leonerd

0001-Warn-if-PERL5OPTS-is-set.patch
From 162bbc29e52785f4d3f3d5f71fd92955472658d5 Mon Sep 17 00:00:00 2001
From: "Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk>
Date: Sat, 8 Dec 2018 19:54:25 +0000
Subject: [PATCH] Warn if PERL5OPTS is set

---
 perl.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/perl.c b/perl.c
index 739ec7ef02..306e260399 100644
--- a/perl.c
+++ b/perl.c
@@ -2272,6 +2272,9 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
 	    }
 	}
     }
+    else if(PerlEnv_getenv("PERL5OPTS"))
+	Perl_warner(aTHX_ packWARN(WARN_MISC),
+	    "The PERL5OPTS environment variable is set - did you mean PERL5OPT instead?\n");
     }
 
 #ifndef NO_PERL_INTERNAL_RAND_SEED
-- 
2.19.2

@p5pRT
Copy link
Author

p5pRT commented Dec 9, 2018

From dcmertens.perl@gmail.com

Merijn,

They must be using some kind of fuzzy string matching (
https://en.wikipedia.org/wiki/Edit_distance). I think that fuzzy string
matching only makes sense for variable and function names, where the
language is *given* a string (i.e. variable or function name) and is asked
to look it up. Probing the environment is different. For that, the language
is giving the string and the environment is asked to look it up.

On the one hand, I think this is a bad idea. Compared to a basic
environment variable lookup by name, it would be rather costly to get all
environment variable names and perform fuzzy matching. On the other hand,
if Perl implemented this *in* *general* for environment variable lookups,
it could make a whole slew of diagnostics *much* more helpful. For example,
if my script asks for $ENV{SOME_THING} but I erroneously set SOMETHING,
Perl's fuzzy matching on %ENV misses could warn about which variable was
set. Furthermore, given that fuzzy matching would only fire on environment
lookup misses, the cost of fuzzy matching would be fairly small in the
grand scheme of things.

The next natural step would be suggesting variable or function names when
mis-spellings are found. Another step, suggesting keys when hash
mis-spellings are found, seems like it would be too far unless we
introduced new syntax for this behavior (i.e. $foo->{{name}} could die with
a fuzzy matching suggestion on mis-spellings).

David

On Fri, Dec 7, 2018 at 2​:17 AM H.Merijn Brand <h.m.brand@​xs4all.nl> wrote​:

On Thu, 06 Dec 2018 12​:28​:04 -0800, "James E Keenan via RT" <
perlbug-followup@​perl.org> wrote​:

On Mon, 19 Nov 2018 17​:07​:44 GMT, leonerd@​leonerd.org.uk wrote​:

I often forget the name of the variable and get confused when (e.g.)

$ PERL5OPTS=-MDevel​::Cover prove -r

doesn't work. The variable name I wanted was PERL5OPT.

I wonder if core could add a little

if (getenv ("PERL5OPTS"))
warn "PERL5OPTS is set; did you mean to set PERL5OPT instead?";

If you could propose a patch (including a test), that would probably
move discussion forward.

Maybe perl6 people could help/chime in

$ perl6 -e'my $perl5opt = "monkey"; say $perl5opts'
===SORRY!=== Error while compiling -e
Variable '$perl5opts' is not declared. Did you mean '$perl5opt'?
at -e​:1
------> my $perl5opt = "monkey"; say ⏏$perl5opts

So they already have the feature to do it for variables, why not
steal/borrow their logic for our environmental variables

And that could trigger someone else to do it for variables in perl5
too :)

--
H.Merijn Brand http​://tux.nl Perl Monger http​://amsterdam.pm.org/
using perl5.00307 .. 5.29 porting perl5 on HP-UX, AIX, and openSUSE
http​://mirrors.develooper.com/hpux/ http​://www.test-smoke.org/
http​://qa.perl.org http​://www.goldmark.org/jeff/stupid-disclaimers/

--
"Debugging is twice as hard as writing the code in the first place.
  Therefore, if you write the code as cleverly as possible, you are,
  by definition, not smart enough to debug it." -- Brian Kernighan

@p5pRT
Copy link
Author

p5pRT commented Dec 9, 2018

From @Tux

On Sun, 9 Dec 2018 05​:45​:01 -0500, David Mertens
<dcmertens.perl@​gmail.com> wrote​:

Merijn,

They must be using some kind of fuzzy string matching (
https://en.wikipedia.org/wiki/Edit_distance). I think that fuzzy string
matching only makes sense for variable and function names, where the
language is *given* a string (i.e. variable or function name) and is asked
to look it up. Probing the environment is different. For that, the language
is giving the string and the environment is asked to look it up.

On the one hand, I think this is a bad idea. Compared to a basic
environment variable lookup by name, it would be rather costly to get all
environment variable names and perform fuzzy matching. On the other hand,
if Perl implemented this *in* *general* for environment variable lookups,
it could make a whole slew of diagnostics *much* more helpful. For example,
if my script asks for $ENV{SOME_THING} but I erroneously set SOMETHING,
Perl's fuzzy matching on %ENV misses could warn about which variable was
set. Furthermore, given that fuzzy matching would only fire on environment
lookup misses, the cost of fuzzy matching would be fairly small in the
grand scheme of things.

IMHO fuzzy lookup should *only* be implemented at compile-time logic,
otherwise the implication would be a noticeable slowdown. The gain of
clear and helping error messages on compile-failing scripts would be a
welcome addition.

Furthermore, %ENV is a tricky one, as you cannot check compile-time
which variables will be set run-time​: $ENV{DBI_DSN} can be set from a
config file, maybe even in a BEGIN {} block

The next natural step would be suggesting variable or function names when
mis-spellings are found. Another step, suggesting keys when hash
mis-spellings are found, seems like it would be too far unless we
introduced new syntax for this behavior (i.e. $foo->{{name}} could die with
a fuzzy matching suggestion on mis-spellings).

Again, only for compile-time fails, otherwise all mixin-like modules
will fail

I for one do *not* like the exception code for one single misspelling
(like $PERL5OPTS). Either do it for all variables that matter at
startup ($PERL5LIB, $PERLIO, ...) or not at all

David

On Fri, Dec 7, 2018 at 2​:17 AM H.Merijn Brand <h.m.brand@​xs4all.nl> wrote​:

On Thu, 06 Dec 2018 12​:28​:04 -0800, "James E Keenan via RT" <
perlbug-followup@​perl.org> wrote​:

On Mon, 19 Nov 2018 17​:07​:44 GMT, leonerd@​leonerd.org.uk wrote​:
[...]

If you could propose a patch (including a test), that would probably
move discussion forward.

Maybe perl6 people could help/chime in

$ perl6 -e'my $perl5opt = "monkey"; say $perl5opts'
===SORRY!=== Error while compiling -e
Variable '$perl5opts' is not declared. Did you mean '$perl5opt'?
at -e​:1
------> my $perl5opt = "monkey"; say ⏏$perl5opts

So they already have the feature to do it for variables, why not
steal/borrow their logic for our environmental variables

And that could trigger someone else to do it for variables in perl5
too :)

--
H.Merijn Brand http​://tux.nl Perl Monger http​://amsterdam.pm.org/
using perl5.00307 .. 5.29 porting perl5 on HP-UX, AIX, and openSUSE
http​://mirrors.develooper.com/hpux/ http​://www.test-smoke.org/
http​://qa.perl.org http​://www.goldmark.org/jeff/stupid-disclaimers/

@p5pRT
Copy link
Author

p5pRT commented Dec 29, 2018

From @xsawyerx

[Top posting]

We can either detect similarity or specific wrongly-spelled. We should
not be doing this for any mismatch, only similar ones.

* If it's fuzzy, we assume the fuzziness does not mean anything.
$ENV{'THING'} is very similar to $ENV{'THINGS'} but for a real reason.
The case that raised this ticket was this exact example in which it
*was* the mistake vs. the right thing, but it could just as easily been
the wrong thing.

* If there was some "ownership" of a list of options, we could maintain
that. For example, /^PERL5/ and then we can maintain they are not
touched if it's not the right one. But then we're getting into
compat-land. We are removing something someone might already be
depending on ($ENV{'PERL5OPT_MINE'}, which might be used).

* We can support specific options (per Paul's patch) but then we're just
arbitrarily picking options. Should we just catch all plurals of our
singular ones (and vice versa)? Should we just add them as we go along?

In the long term, perhaps a Perl5-owned list of environment variables
would serve the user best, but we are both limiting how they use their
own environment variables *and* we are breaking any code that depends on
similar entries.

The last option of specifics is also available, but it requires picking
up a system to decide which are supported and why.

The first option of fuzzy matching is, by far, my least favorite. It's
error-prone, inconsistent, and adds far more costs than exact (or
prefixed) matches.

On 12/9/18 1​:03 PM, H.Merijn Brand wrote​:

On Sun, 9 Dec 2018 05​:45​:01 -0500, David Mertens
<dcmertens.perl@​gmail.com> wrote​:

Merijn,

They must be using some kind of fuzzy string matching (
https://en.wikipedia.org/wiki/Edit_distance). I think that fuzzy string
matching only makes sense for variable and function names, where the
language is *given* a string (i.e. variable or function name) and is asked
to look it up. Probing the environment is different. For that, the language
is giving the string and the environment is asked to look it up.

On the one hand, I think this is a bad idea. Compared to a basic
environment variable lookup by name, it would be rather costly to get all
environment variable names and perform fuzzy matching. On the other hand,
if Perl implemented this *in* *general* for environment variable lookups,
it could make a whole slew of diagnostics *much* more helpful. For example,
if my script asks for $ENV{SOME_THING} but I erroneously set SOMETHING,
Perl's fuzzy matching on %ENV misses could warn about which variable was
set. Furthermore, given that fuzzy matching would only fire on environment
lookup misses, the cost of fuzzy matching would be fairly small in the
grand scheme of things.
IMHO fuzzy lookup should *only* be implemented at compile-time logic,
otherwise the implication would be a noticeable slowdown. The gain of
clear and helping error messages on compile-failing scripts would be a
welcome addition.

Furthermore, %ENV is a tricky one, as you cannot check compile-time
which variables will be set run-time​: $ENV{DBI_DSN} can be set from a
config file, maybe even in a BEGIN {} block

The next natural step would be suggesting variable or function names when
mis-spellings are found. Another step, suggesting keys when hash
mis-spellings are found, seems like it would be too far unless we
introduced new syntax for this behavior (i.e. $foo->{{name}} could die with
a fuzzy matching suggestion on mis-spellings).
Again, only for compile-time fails, otherwise all mixin-like modules
will fail

I for one do *not* like the exception code for one single misspelling
(like $PERL5OPTS). Either do it for all variables that matter at
startup ($PERL5LIB, $PERLIO, ...) or not at all

David

On Fri, Dec 7, 2018 at 2​:17 AM H.Merijn Brand <h.m.brand@​xs4all.nl> wrote​:

On Thu, 06 Dec 2018 12​:28​:04 -0800, "James E Keenan via RT" <
perlbug-followup@​perl.org> wrote​:

On Mon, 19 Nov 2018 17​:07​:44 GMT, leonerd@​leonerd.org.uk wrote​:
[...]
If you could propose a patch (including a test), that would probably
move discussion forward.
Maybe perl6 people could help/chime in

$ perl6 -e'my $perl5opt = "monkey"; say $perl5opts'
===SORRY!=== Error while compiling -e
Variable '$perl5opts' is not declared. Did you mean '$perl5opt'?
at -e​:1
------> my $perl5opt = "monkey"; say ⏏$perl5opts

So they already have the feature to do it for variables, why not
steal/borrow their logic for our environmental variables

And that could trigger someone else to do it for variables in perl5
too :)

@khwilliamson
Copy link
Contributor

Instead of a general solution, why can't we just accept either spelling of this variable?

@Tux
Copy link
Contributor

Tux commented Apr 24, 2023

One reason I can come up with: both are defined. In that case: which will take precedence?
What if both are defined and they conflict?

@khwilliamson
Copy link
Contributor

khwilliamson commented Apr 24, 2023 via email

@haarg
Copy link
Contributor

haarg commented Apr 24, 2023

There are many pieces of code that try to isolate themselves from outside variables, for testing and similar cases. This would add an additional variable that would need to be localized. Most likely, the code trying to do that would not be updated, and would instead start to fail when PERL5OPTS was used.

@Tux
Copy link
Contributor

Tux commented Apr 30, 2023

We've discussed this during the PTS in Lyon and came to the conclusion that supporting both is not an option (pun intended).
Closing

@Tux Tux closed this as completed Apr 30, 2023
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

5 participants