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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:51:47+00:00 2026-05-13T17:51:47+00:00

The new method of Parse::RecDescent has this prototype: sub new ($$$) { # code

  • 0

The new method of Parse::RecDescent has this prototype:

sub new ($$$)
{
   # code goes here
}

and if I create an object like this:

my $parser = Parse::RecDescent->new($grammar);

it will create a parser, and the method will receive 2 parameters “Parse::RecDescent” and $grammar, right? If I try to create an object like:

Parse::RecDescent::new("Parse::RecDescent",$grammar)

this will fail saying “Not enough arguments for Parse::RecDescent::new”, and I understand this message. I’m only passing 2 parameters. However, I don’t understand why the arrow version works.

Can you explain?

  • 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-13T17:51:48+00:00Added an answer on May 13, 2026 at 5:51 pm

    Function prototypes are not checked when you call it as an OO-style method. In addition, you bypass prototype checking when you call a sub with &, as in &sub(arg0, arg1..);

    From perldoc perlsub:

    Not only does the “&” form make the argument list optional, it also disables any prototype checking on arguments you do provide. This is partly for
    historical reasons, and partly for having a convenient way to cheat if you know what you’re doing. See Prototypes below.

    Method calls are not influenced by prototypes either, because the function to be called is indeterminate at compile time, since the exact code called depends on inheritance.

    While Parse::RecDescent::new("Parse::RecDescent", $grammar) is syntactically correct, that’s a pretty smelly way of calling the constructor, and now you are forcing it to be defined in that class (rather than in an ancestor). If you really need to validate your arguments, do it inside the method:

    sub new
    {
        my ($class, @args) = @_;
        die "Not enough arguments passed to constructor" if @args < 2;
        # ...
    }
    

    See also this earlier question on prototypes and why they aren’t usually such a great idea.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer IT would depend on your SQL server, in Postgres/Oracle I'd… May 13, 2026 at 9:39 pm
  • Editorial Team
    Editorial Team added an answer I'd just write: vector<string> args(argv + 1, argv + argc… May 13, 2026 at 9:38 pm
  • Editorial Team
    Editorial Team added an answer I had read that article but it didn't give me… May 13, 2026 at 9:38 pm

Related Questions

I am new to the iphone platform and am creating an app that retrievals
I need to calculate if someone is over 18 from their date of birth
My application needs to keep track of RSS/Atom feeds and save the new entries
I have method that transforms some input value by the user passing it a
I would like to take a string representation of a set and parse it.

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.