perl: run another script without exec/system

Is it possible to include/source another perl script, or launch it as a "sub"? This works, but looks ugly:

test2.pl:

print "I'm in test2.pl; args: @ARGV\n";

test.pl:

#!/usr/bin/perl

use File::Temp qw/tempdir/;
use File::Copy qw/copy/;

my $tmplib;

use lib ($tmplib = tempdir()) . (
  copy("./test2.pl", "$tmplib/test2.pm") ? "" : (die "$!")
  );

use test2;

x

$ ./test.pl a b c
I'm in test2.pl; args: a b c

Answers


It sounds like you want the do operator, although it also sounds like very bad design.

This is what the documentation says.

do EXPR Uses the value of EXPR as a filename and executes the contents
        of the file as a Perl script.
            do 'stat.pl';

        is just like

            eval `cat stat.pl`;

Need Your Help

Determine dates of DST switch (both forwards and backwards) for a timezone in Java?

java datetime date dst

I realize that you can check if a Date is inDaylightTime, but how can I determine when (or if) that Date switches to and from DST? I can iterate over every day and check if it's inDaylightTime, but...

Replace character in all database fields

sql-server quotes double-quotes

We received an MSSQL database with many tables and fields which we need to clean. One of the things we need to do is remove all quotes (chr(34) and chr(39)) from any text fields.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.