Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
You could indeed use eval, but you then have the tricky task of validating the name of the dependency first.

I think that you should validate the name in any case. BTW: Taint mode enforces that you validate the name.

/tmp>cat taint-require.pl #!/usr/bin/perl -T use strict; use warnings; my $mod=<STDIN>; chomp $mod; $mod.='.pm'; $mod=~s!(::|')!/!g; require $mod; print $mod->VERSION; /tmp>chmod +x taint-require.pl /tmp>echo Data::Dumper | taint-require.pl Insecure dependency in require while running with -T switch at ./taint +-require.pl line 11, <STDIN> line 1. /tmp>
$dep =~ s{::}{/}g; $dep .= ".pm"; require $dep;

That's strictly speaking not sufficient. ' can be used as a separator in module names in place of :: (perl4 legacy). Some fun modules, like Acme::Don't, still use this feature. And perl still accepts ' in place of :::

/tmp>cat perl4-mod.pl #!/usr/bin/perl use strict; use warnings; use Data'Dumper; print Dumper(\%INC); /tmp>perl perl4-mod.pl $VAR1 = { 'warnings/register.pm' => '/usr/share/perl5/warnings/registe +r.pm', 'strict.pm' => '/usr/share/perl5/strict.pm', 'constant.pm' => '/usr/share/perl5/constant.pm', 'warnings.pm' => '/usr/share/perl5/warnings.pm', 'overload.pm' => '/usr/share/perl5/overload.pm', 'Exporter.pm' => '/usr/share/perl5/Exporter.pm', 'overloading.pm' => '/usr/share/perl5/overloading.pm', 'Carp.pm' => '/usr/share/perl5/Carp.pm', 'XSLoader.pm' => '/usr/local/lib64/perl5/XSLoader.pm', 'Data/Dumper.pm' => '/usr/lib64/perl5/Data/Dumper.pm', 'bytes.pm' => '/usr/share/perl5/bytes.pm' }; /tmp>perl -v This is perl 5, version 22, subversion 2 (v5.22.2) built for x86_64-li +nux-thread-multi Copyright 1987-2015, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge. /tmp>

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^2: Use 'use' in foreach by afoken
in thread Use 'use' in foreach by zidi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-25 12:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found