Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8125407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:48:20+00:00 2026-06-06T06:48:20+00:00

I’m working on a bot in Perl (based on POE) and so far so

  • 0

I’m working on a bot in Perl (based on POE) and so far so good, but I can’t figure out how can I add a !js or !perl command to evaluate respective code and return one line of output to be printed into the channel. I found App::EvalServer but I don’t get how to use it.

Thanks for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:48:22+00:00Added an answer on June 6, 2026 at 6:48 am

    The App::EvalServer module comes with a binary to run as a standalone application. You do not put it in your program but rather run it on it’s own. It opens a port where you can hand it code as a json string. This does not sound like a good idea to me either.

    There is another module you might want to look at called Safe. I suggest you read through the complete documentation as well as the one to Opcode (linked in the doc) before you do anything with this. YOU CAN DO SERIOUS DAMAGE IF YOU EVALUATE ARBITRARY CODE! Never forget that.


    UPDATE:

    Here’s an example of how to capture the output of print or say from your evaled code. You can use open with a variable to make printed output always go to that variable. If you switch back afterwards you can work with the captured output in your var. This is called an in-memory file.

    use strict; use warnings;
    use feature 'say'; 
    use Safe;
    
    # Put our STDOUT into a variable
    my $printBuffer;
    open(my $buffer, '>', \$printBuffer);
    # Everything we say and print will go into $printBuffer until we change it back
    my $stdout = select($buffer);
    
    # Create a new Safe
    my $compartment = new Safe;
    $compartment->permit(qw(print)); # for testing
    
    # This is where the external code comes in:
    my $external_code = qq~print "Hello World!\n"~;
    
    # Execute the code
    my $ret = $compartment->reval($external_code, 1);
    
    # Go back to STDOUT
    select($stdout);
    
    printf "The return value of the reval is: %d\n", $ret;
    say "The reval's output is:";
    say $printBuffer;
    
    # Now you can do whatever you want with your output
    $printBuffer =~ s/World/Earth/;
    say "After I change it:";
    say $printBuffer;
    

    Disclaimer: Use this code at your own risk!


    Update 2: After a lengthy discussion in chat, here’s what we came up with. It implements a kind of timeout to stop the execution if the reval is taking to long, e.g. because of an infinite loop.

    #!/usr/bin/perl
    use warnings;
    use strict;
    use Safe;
    use Benchmark qw(:hireswallclock);
    
    my ($t0, $t1); # Benchmark
    my $timedOut = 0;
    my $userError = 0;
    my $printBuffer;
    open (my $buffer, '>', \$printBuffer);
    my $stdout = select($buffer);
    my $cpmt = new Safe;
    $cpmt->permit_only(qw(:default :base_io sleep));
    eval
    {
            local $SIG{'ALRM'} = sub { $timedOut = 1; die "alarm\n"};
            $t0 = Benchmark->new;
            alarm 2;
            $cpmt->reval('print "bla\n"; die "In the user-code!";');
    #         $cpmt->reval('print "bla\n"; sleep 50;');
            alarm 0;
            $t1 = Benchmark->new;
            if ($@)
            {
                    $userError = "The user-code died! $@\n";
            }
    };
    select($stdout);
    
    
    if ($timedOut)
    {
            print "Timeout!\n";
            my $td = timediff($t1, $t0);
            print timestr($td), "\n";
            print $printBuffer;
    }
    else
    {
            print "There was no timeout...\n";
            if ($userError)
            {
                    print "There was an error with your code!\n";
                    print $userError;
                    print "But here's your output anyway:\n";
                    print $printBuffer;
            }
            else
            {
              print $printBuffer;
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.