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 8307941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:39:14+00:00 2026-06-08T18:39:14+00:00

I am using reval from Perl’s Safe module and I want to prevent it

  • 0

I am using reval from Perl’s Safe module and I want to prevent it from generating warnings if the string being eval’ed can’t be parsed (actually, I want to prevent it from generating any warnings at all).

For example, the following code:

use strict; use warnings;
use Safe;    
use feature qw/say/;
my $cft = Safe->new;

my $x = $cft->reval(') 1' );
my $y = $cft->reval('2'   );
say "x: $x";
say "y: $y";

results in:

Number found where operator expected at (eval 5) line 1, near ") 1"
    (Missing operator before 1?)
Use of uninitialized value $x in concatenation (.) or string at ./test line 12.
x: 
y: 2

What I’m trying to achieve is to have $x = undef and $y = 2, and no warnings.
I tried to put a “no warnings;” inside a new scope, but it has no effect on the warnings produced from within the reval (although, as pointed out by @DavidO, it silences the ‘uninitialized value’ warning):

use strict; use warnings;
use Safe;    
use feature qw/say/;
my $cft = Safe->new;
{
    no warnings;
    my $x = $cft->reval(') 1' );
    my $y = $cft->reval('2'   );
    say "x: $x";
    say "y: $y";
}

I guess that somehow the ‘no warnings’ has to be inside the Safe compartment, so I also tried to prepend “no warnings;” to the strings being eval’ed:

use strict; use warnings;
use Safe;
use feature qw/say/;
my $cft = Safe->new;
{
    my $x = $cft->reval( 'no warnings;' . ') 1' );
    my $y = $cft->reval( 'no warnings;' . '2'   );
    say "x: $x";
    say "y: $y";
}

This way reval does not issue any warnings, but both variables are undef:

Use of uninitialized value $x in concatenation (.) or string at ./test line 10.
x: 
Use of uninitialized value $y in concatenation (.) or string at ./test line 11.
y:

I don’t know what else to try, and I hope that the problem description was clear enough.

  • 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-08T18:39:16+00:00Added an answer on June 8, 2026 at 6:39 pm

    If you check $@ you’ll see that $cft->reval( 'no warnings;' . ') 1' ); failed. 'require' trapped by operation mask at (eval 5) line 1.. In other words, Safe is doing its job and preventing that code from trying to load a library.

    $cft->reval( 'BEGIN { warnings->unimport; } ) 1' ); would work, presuming warnings is already loaded outside the compartment. However, that won’t quiet compile time errors. Unlike eval, reval seems to let them through. Use amon’s technique of quieting STDERR.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm calling a .net webservice from Linux using Perl (5.8.7). I'm using the SOAP::Lite
How can I remove capturing from arbitrarily nested sub-groups in a a Perl regex
I am writing a Perl script and using the Class::CSV module. I have an
In pom.xml I have (taken from http://struberg.wordpress.com/2012/05/10/using-jpa-in-real-projects-part-1/ ): <properties> <openjpa.sql.action>refresh</openjpa.sql.action> <database.driver.name>org.postgresql.Driver</database.driver.name> <database.connection.url>jdbc:postgresql://myURL</database.connection.url> <database.user>user</database.user> <database.password>password</database.password>
I'm pulling content from a DB that has been sanitized using mysql_real_escape_string. Accordingly the
I'm attempting to move a web app we have (written in Perl) from an
How can I match finite natural number series with regex? So, requirements are: string
I'm receiving byte data from a VNC server, using Real VNC this works in
I've been using base64_encode to preserve html from a <textarea> form and storing the
I'm using Matlab and need to get an ASAP2 (a2l) file exported from a

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.