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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:43:41+00:00 2026-05-19T12:43:41+00:00

In the following anonymous subroutine declaration, Perl seems to be parsing it as an

  • 0

In the following anonymous subroutine declaration, Perl seems to be parsing it as an indirect method call, rather than as a subroutine:

use 5.010;
use strict;
use warnings;

sub proxy {
    my $new = shift;
    say "creating proxy: $new";
    sub :lvalue {
        say "running proxy: $new";
        tie my $ret, 'Some::Package', shift, $new;
        $ret
    }
}

say "before";
my $p1 = proxy '_value';
say "p1 declared: $p1";
my $p2 = proxy 'value';
say "p2 declared: $p2";

which prints:

before
creating proxy: _value
running proxy: _value
Can't locate object method "TIESCALAR" via package "Some::Package" ...

If a return or my $sub = is added right before sub :lvalue {..., then everything works properly, and it prints:

before
creating proxy: _value
p1 declared: CODE(0x4c7e6c)
creating proxy: value
p2 declared: CODE(0x1ea85e4)

It also works if the :lvalue attribute is removed from the subroutine (but of course that changes the functionality).

So my question is why is this happening? Is this a bug in Perl related to attributes on anonymous subroutines? Is it for some reason an expected behavior? If it is a bug, is it registered?

  • 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-19T12:43:41+00:00Added an answer on May 19, 2026 at 12:43 pm

    Because the beginning of a statement is a valid place to find a goto label, and so the bareword sub followed by a colon token is parsed as the label sub:, which is followed by lvalue BLOCK, which is parsed as indirect object syntax.

    If you force the parser to look for a term by doing return sub : lvalue { ... } or my $foo = sub : lvalue { ... } it parses as intended.

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

Sidebar

Related Questions

I am trying to use Expression Trees and anonymous types to achieve the following.
Can't I have an anonymous delegate declaration, something similar to the following: ThreadStart starter
The following is a method for defining an anonymous function within a closure, invoke
I'm gonna create a BackgroundWorker with an anonymous method. I've written the following code
In the following code I have placed anonymous structures inside of my class declaration
I'm attempting to use the following code to serialize an anonymous type to JSON:
In the following code upto what scope the anonymous array referred by $ref is
How can I create an anonymous and curried function in Scala? The following two
I have the following anonymous function: (function() { var a = 1; var b
I have the following anonymous type: new {data1 = test1, data2 = sam, data3

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.