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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:26:22+00:00 2026-05-11T02:26:22+00:00

I am writing a Perl module, and I am using carp to throw a

  • 0

I am writing a Perl module, and I am using carp to throw a non-fatal warning back to the calling program.

The carp warning works fine – I am checking if an input parameter meets a certain condition – if it does not meet the condition, a warning is sent with carp and the module continues on using a default for the parameter instead of the one the calling program passed. The warning is just to notify that a default parameter is being used instead of the passed in parameter.

My problem is with my test script. My test script is sending in a bad parameter to the module, and I am trying to catch the warning message that comes back and make sure I got the correct warning message.

My module looks something like this:

else {   carp "value must be numeric - using default value"; } 

and my test script looks like this:

eval {   #call to my module }; like (     $@,     qr/value must be numeric/,     "Should abort on non-numeric value" ); 

When I run the test, I can see the warning (it must be going to STDERR) on the screen, but the contents of the $@ variable is ” – blank.

Here is the output from my test script:

t/04bad_method_calls....ok 10/12value must be numeric - using default value at ... #   Failed test 'Should abort on non-numeric value' #   at t/04bad_method_calls.t line 98. t/04bad_method_calls....NOK 12 #                   '' doesn't match '(?-xism:value must be numeric)' # Looks like you failed 1 test of 12. 

If I change the carp to a croak, my test script works – it catches the error message (but I only want to warn, not abort).

To be honest, I don’t have the best understanding of eval – maybe that is not the best way to catch the warning output from carp. I tried using $SIG{__WARN__}, but that was empty as well.

Is there any way to capture the output from carp? It’s not the biggest deal since this is just in my test script, but I’d still like to get my test script to work properly.

Thanks in advance!

  • 1 1 Answer
  • 2 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. 2026-05-11T02:26:23+00:00Added an answer on May 11, 2026 at 2:26 am

    From this page, http://perldoc.perl.org/perlvar.html, it looks like you want to set the local $SIG{__WARN__} to a subroutine that will turn warnings into fatal errors for your test script. The example they give is:

    local $SIG{__WARN__} = sub { die $_[0] }; eval $proggie; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 104k
  • Answers 104k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It seems to me that you're looking for numbers that… May 11, 2026 at 8:35 pm
  • Editorial Team
    Editorial Team added an answer Check out a personal branch of the code and merge… May 11, 2026 at 8:35 pm
  • Editorial Team
    Editorial Team added an answer The easiest solution is to embed the SWF within a… May 11, 2026 at 8:35 pm

Related Questions

I am writing a kid sister encryption function and I need a PRNG that
I am writing a Perl script that is searching for a term in large
I have taken over maintenance of a very large (>2M SLOC) software project, all
I am going to spend 30 minutes teaching Perl to an experienced programmer. The

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.