in reply to Where does the spurious error message come from?

G'day kikuchiyo,

This is intended mainly as a confirmation that the problem was fixed in v5.38. I put "BEGIN { say $^V }" near the top of the script but otherwise left your code as is. I tried with v5.36.0 and v5.38.0 (I don't have v5.36.1 available).

v5.36.0 Global symbol "$undeclared_variable" requires explicit package name .. +. Type of arg 1 to List::Util::any must be block or sub {} (not referenc +e constructor) ...
v5.38.0 Global symbol "$undeclared_variable" requires explicit package name .. +.

After uncommenting the my declaration:

v5.36.0 Printing inside foo() Printing inside bar()
v5.38.0 Printing inside foo() Printing inside bar()

— Ken

Replies are listed 'Best First'.
Re^2: Where does the spurious error message come from?
by cavac (Prior) on Aug 05, 2023 at 20:32 UTC

    Less confusing error messages? What i strange concept!

    Truth be told, i love it but i never expected that i would ever see it happen.

    Sadly though, my idea of a contains() function for arrays was refused by the core team, so array checking is still ugly and error-prone. Guess i have to be content with ONE major improvement per release. I mean, i have Array::Contains, but that only runs at a fraction of the speed of a native solution...

    PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP

      How does it compare speed-wise with List::Util::any? I've always found that fast enough for my needs but maybe I'm just not very demanding.


      🦛

        "How does it compare speed-wise ..."

        A very quick benchmark shows no appreciable difference.

        #!/usr/bin/env perl use strict; use warnings; use Array::Contains; use List::Util 'any'; use Benchmark 'cmpthese'; my @base = 'A' .. 'Z'; my @search = map +($_, lc), @base; print "\@base[@base]\n"; print "\@search[@search]\n"; cmpthese 0 => { lua => \&lua, acc => \&acc, }; sub lua { for my $x (@search) { my $bool = any { $_ eq $x } @base; } return; } sub acc { for my $x (@search) { my $bool = contains($x, \@base); } return; }

        The check on the arrays was the same on each run:

        @base[A B C ... X Y Z] @search[A a B b C c ... X x Y y Z z]

        Here's the results of three runs:

        Rate lua acc lua 15544/s -- -1% acc 15622/s 1% -- Rate acc lua acc 15777/s -- -1% lua 15905/s 1% -- Rate acc lua acc 15782/s -- -0% lua 15857/s 0% --

        — Ken