develooper Front page | perl.perl5.porters | Postings from December 2018

Re: [perl #133669] Silently ignores commonly-misspelled PERL5OPTSenvironment variable

Thread Previous | Thread Next
From:
David Mertens
Date:
December 9, 2018 10:45
Subject:
Re: [perl #133669] Silently ignores commonly-misspelled PERL5OPTSenvironment variable
Message ID:
CA+4ieYW5wbbSUd5y12CjWrNDO0w9e8=fhTu54ex=XJA_DW63_Q@mail.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

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About