in reply to What's your favourite method of untainting?

$foo = each %{{$foo,0}}

Replies are listed 'Best First'.
Re^2: What's your favourite method of untainting?
by bliako (Abbot) on Nov 09, 2023 at 17:56 UTC

    thanks for this. As it now issues the warning (perl v5.36.0):

    each on anonymous hash will always start from the beginning

    I propose this variation: ($foo) = keys %{{$foo,0}}

    Also, here is a test script using Test::Taint to check taintness:

    #!perl -T use strict; use warnings; use Test::More; use Test::Taint; my $foo = "ababab"; taint($foo); tainted_ok($foo, "foo is tainted"); ($foo) = keys %{{$foo,0}}; untainted_ok($foo, "foo is now untainted"); done_testing;

    bw, bliako

      Or $foo = (keys %{{$foo,0}})[0]
      --
      A math joke: r = | |csc(θ)|+|sec(θ)| |-| |csc(θ)|-|sec(θ)| |