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

  • SEARCH
  • Home
  • 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 9273839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:12:28+00:00 2026-06-18T16:12:28+00:00

Should a subroutine croak when called with more arguments than expected or should the

  • 0

Should a subroutine croak when called with more arguments than expected or should the extra arguments simply be ignored?

#!/usr/bin/env perl
use warnings;
use strict;


sub routine {
    my ( $a, $b ) = @_;
    return $a * $b;
}

my $reslult = routine( 4, 5, 6 );
  • 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-18T16:12:29+00:00Added an answer on June 18, 2026 at 4:12 pm

    Generally I don’t bother writing argument checks by hand, but I think the correct response is to croak. That way you can extend the function to take optional arguments later without breaking existing callers.

    If your Perl is new enough, you can install and use Function::Parameters like this:

    use warnings;
    use strict;
    use Function::Parameters qw(:strict);
    
    fun routine($x, y) {
        return $x * $y;
    }
    
    my $result = routine(4, 5, 6);  # croaks automatically
    

    (Btw, don’t call your variables $a or $b: those names are used by sort and exempt from strict 'vars' checks.)

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

Sidebar

Related Questions

Good practice dictates that subroutine arguments in Fortran should each have a specified intent
I have a subroutine in Perl that should be indented like this: sub GetFiles
Possible Duplicate: When should I use the & to call a Perl subroutine? I
I've got a perl subroutine that should return the number of primes between a
Should createUrl be called on controller or in views ? It doesn't matter? Or
I have a subroutine called debug I use in my code. It basically allows
We should all be familiar with the problems related to prototypes in Perl. Here
I have a Perl subroutine which updates an RSS feed. I want to test
I don't grok Perl subroutine attributes at all. I have never seen them in
How should I define a Moose object subroutine after its initialization? I'm writing an

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.