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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:54:49+00:00 2026-05-28T01:54:49+00:00

In my code, I’m been using the fairly primitive method of extraction parameters from

  • 0

In my code, I’m been using the fairly primitive method of extraction parameters from a function call as follows:

sub addSix ($$$$$$) {
    my ($a, $b, $c, $d, $e, $f) = (shift, shift, shift, shift, shift, shift);
    return $a + $b + $c + $d + $e + $f;
}

print addSix (1, 2, 3, 4, 5, 6) . "\n";

(forget the primitive code, the salient bit is the multiple shift calls).

Now that seems rather messy to me and I though Perl may have something like:

my ($a, $b, $c, $d, $e, $f) = shift (6);

or something similar.

But I cannot find anything like that. I know I can use arrays for this but I think I’d still have to unpack the array into individual scalars. That wouldn’t be too bad for the example case above, where the six parameters are similar, but I’m more interested in the case where they’re not really suitable as an array.

How can you extract parameters without ending up with a morass of shift keywords?

  • 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-05-28T01:54:50+00:00Added an answer on May 28, 2026 at 1:54 am

    You can simply type:

    my ($a, $b, $c, $d, $e, $f) = (@_);
    

    If you didn’t have that prototype, and if that sub got called with more than six arguments, the ones after the sixth are simply “not matched”, $f would be set to the sixth argument.

    If you want to catch all the arguments after the sixth, you can do it like this.

    my ($a, $b, $c, $d, $e, $f, @others) = (@_);
    

    If your list of scalars is longer than the list on the right side, the last elements will be undef.

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

Sidebar

Related Questions

code snippet: //byte[] myByteArray = byte array from database (database BLOB) myByteArray = (byte[])
Code in the post has been modified. I was thinking that replacing \n with
Code snippet from here : void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char
Code snippet from here : void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char
Code below sets default values for new row if row is added using form.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Code: #include <iostream> using namespace std; #define ADD(x,y) ((x)+(y)) int main( int argc, char**
Code as follows: <meta http-equiv=Content-type content=text/html; charset=utf8 /> But when I browse the page
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {

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.