in reply to Re: FindBin and Tainted
in thread FindBin and Tainted

This works. But is there any way to do the same without using the same $RealBin variable (which belongs to FindBin)?

Replies are listed 'Best First'.
Re^3: FindBin and Tainted
by haj (Vicar) on Aug 15, 2020 at 08:55 UTC

    Sure, you can use a copy, to be declared outside of the BEGIN block:

    use strict; use warnings; use FindBin 1.51 qw( $RealBin ); my $untainted_bin; BEGIN { ($untainted_bin) = $RealBin =~ /(.+)/; } use lib "$untainted_bin/../lib"; use MyLib;
      Thanks. This is beautiful. I improved it a little. Probably more portable with File::Spec.
      use FindBin 1.51 qw( $RealBin ); use File::Spec; my $lib_path; BEGIN { $lib_path = File::Spec->catdir(($RealBin =~ /(.+)/msx)[0], q{..}, +'lib'); } use lib "$lib_path";