use strict; use warnings; use Capture::Tiny ':all'; # anonymonk tip #use File::Temp; # for complex drivers write it to a temp file sub bad { my ($perl_executable, $perl_module_to_require, $perl_code_to_drive_it ) = @_; # capture from external command my $prog = <<EOQ; require "$perl_module_to_require" or die "failed to load module $perl_ +module_to_require"; $perl_code_to_drive_it EOQ # my $tmpfile = File::Temp::tempfile(); print "executing: $perl_executable -I. -e '".$prog."'\n"; my ($stdout, $stderr, $exit) = capture { system( $perl_executable, '-I', '.', '-e', $prog ); }; die "exit=$exit\n $stderr\n" if $exit; print "stdout=$stdout\n"; print "stderr=$stderr\n"; } # and here is the example use bad( '/usr/bin/perl', # perl exec to run 'p5_24.pl', # the file which contains Mul() 'my $res = Mul(6,7); print "$res\n"' # the harness );

there is a reason I named it bad

bw, bliako

Edit: I have now seen the crosspost at https://stackoverflow.com/questions/61085771/invokes-perl-modules-from-perl-script-in-different-perl-versions and I somehow feel I want to say I definetely was not aware about any of the answers there when I answered. One answer, older than mine here, is outlining the above technique.


In reply to Re: Calling perl function from another perl script with different Active perl versions by bliako
in thread Calling perl function from another perl script with different Active perl versions by maria80e

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.