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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:44:13+00:00 2026-05-27T06:44:13+00:00

Just a curiosity, I have played around with prototyping a bit, but it seems

  • 0

Just a curiosity, I have played around with prototyping a bit, but it seems that the prototype & for a subroutine is only allowed in the first position.

When I write

sub test (&$$) {
    do_something;
}

and call it as

test {doing_something_else} 1,2;

it works.

When I prototype like this

sub test ($$&) {
    do_something;
}

and again call it as

test 1,2 {doing_something_else};

it doesn’t work. I tried with various permutations, but nothing seems to deliver.

Am I missing something, or is it not possible? And if not, why?

(I maybe need to specify, that I successfully tried the option of calling test(1, 2, sub{foo}), of course, but it doesn’t look quite as sexy as the option in the last example above (and for that I don’t even need prototyping); I would like to be able to implement the syntax of structures like if () {} else {}, etc. or, more to the point, try () catch () {} or switch () case (){}, but I guess that’s why those constructs have not yet been implemented in Perl)

  • 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-27T06:44:13+00:00Added an answer on May 27, 2026 at 6:44 am

    The & prototype character only takes the block form when it is the first item in a prototype. This is just a limitation of the way perl’s prototype parser works.

    You could always use the sub keyword to create an anonymous subroutine that works fine as an argument in any position without a prototype.

    test 1, 2, sub {doing_something_else};
    

    If you really really want to write it without the sub but not in the first position, you could have fun playing around with Devel::Declare to write your own parse rules for the test subroutine (this is an advanced topic).

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

Sidebar

Related Questions

Just a question for my own curiosity. I have heard many times that it's
Just out of curiosity, for applications that have a fairly complicated module tree, would
I'll start by saying that this isn't a problem, just curiosity. I have some
This is just out of curiosity, but do any of you have an idea
I don't actually need it now, but just out of curiosity... Suppose we have
What happens if I finish the drive letters? It's just curiosity, but I have
I have just a curiosity question. I have an HttpPost request in Android that
Just out of curiosity, how does iostream access the input-output system. (I have a
This is just a curiosity question. I know that Spring can be used in
I know this is a stupid question. But just out of curiosity, is there

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.