Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: FindBin and Tainted

by haj (Curate)
on Aug 15, 2020 at 08:55 UTC ( #11120768=note: print w/replies, xml ) Need Help??


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

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;

Replies are listed 'Best First'.
Re^4: FindBin and Tainted
by mikkoi (Sexton) on Aug 15, 2020 at 20:18 UTC
    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";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11120768]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2021-01-27 07:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?