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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:54:44+00:00 2026-05-31T21:54:44+00:00

A coworker’s typo when calling a subref raised this strange syntax question. If I

  • 0

A coworker’s typo when calling a subref raised this strange syntax question. If I call a subref without the dereference arrow, perl dies with Not a GLOB reference. However, if the subref is called as a method on a blessed object, it runs fine.

What does this have to do with globs? And why does the method call work?

use 5.12.0;
use Try::Tiny;

my $f = sub { 'sub ref' };
my $obj = bless({}, 'Blessed');

try {
   say $f($obj); # should be $f->();
} catch { 
   say "ERROR: $_";
};

say $obj->$f();

Output:

C:\code>perl dispatch.pl
ERROR: Not a GLOB reference at dispatch.pl line 8.

sub ref
  • 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-31T21:54:46+00:00Added an answer on May 31, 2026 at 9:54 pm

    say, like print, accepts an optional filehandle/typeglob to direct output to, eg:

    my $f = \*STDERR;
    say $f ("This goes to stderr.");
    

    I didn’t realize until now that you could do a method call on a subroutine reference, but sure enough, the perlobj man page states:

    If the right side of the arrow is a scalar containing a reference to a
    subroutine, then this is equivalent to calling the referenced subroutine
    directly with the class name or object on the left side of the arrow as its
    first argument. No lookup is done and there is no requirement that the
    subroutine be defined in any package related to the class name or object on the
    left side of the arrow.

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

Sidebar

Related Questions

A coworker of mine has this problem, apparently after installing Re#, which seems totally
A coworker has been struggling with this problem. The desired result is an installable
A coworker showed me this: He has a DropDownList and a button on a
Had a coworker ask me this, and in my brain befuddled state I didn't
A coworker of mine came across this the other day while we were working
Repost from Perlmonks for a coworker: I wrote a perl script to separate long
A coworker was recently asked this when trying to land a (different) research job:
I saw this function in a source written by my coworker private String GetNewAvailableId()
My coworker did this experiment: public class DoubleDemo { public static void main(String[] args)
A coworker routinely writes something like this: ::someObject->someMethod(anAttribute, anotherAttribute); someObject is a global variable.

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.