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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:12:13+00:00 2026-05-21T05:12:13+00:00

I recently saw some Perl code that confused me. I took out all of

  • 0

I recently saw some Perl code that confused me. I took out all of the extra parts to see how it was working, but I still don’t understand why it works.

Basically, I created this dummy “module” (TTT.pm):

use strict;
use warnings;

package TTT;
sub new {
    my $class = shift;
    return bless {'Test' => 'Test'}, $class;
}

sub acquire {
    my $tt = new TTT();
    return $tt;
}
1;

Then I created this script to use the module (ttt.pl):

#!/usr/bin/perl
use strict;
use warnings;

use TTT;
our $VERSION = 1;

my $tt = acquire TTT;
print $tt->{Test};

The line that confuses me, that I thought would not work, is:

my $tt = acquire TTT;

I thought it would not work since the “acquire” sub was never exported. But it does work.
I was confused by the “TTT” after the call to acquire, so I removed that, leaving the line like this:

my $tt = acquire;

And it complained of a bareword, like I thought it would. I added parens, like this:

my $tt = acquire();

And it complained that there wasn’t a main::acquire, like I thought it would.

I’m used to the subroutines being available to the object, or subroutines being exported, but I’ve never seen a subroutine get called with the package name on the end. I don’t even know how to search for this on Google.

So my question is, How does adding the package name after the subroutine call work? I’ve never seen anything like that before, and it probably isn’t good practice, but can someone explain what Perl is doing?

Thanks!

  • 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-21T05:12:13+00:00Added an answer on May 21, 2026 at 5:12 am

    You are using the indirect object syntax that Perl allows (but in modern code is discouraged). Basically, if a name is not predeclared, it can be placed in front of an object (or class name) separated with a space.

    So the line acquire TTT actually means TTT->acquire. If you actually had a subroutine named acquire in scope, it would instead be interpreted as aquire(TTT) which is can lead to ambiguity (hence why it is discouraged).

    You should also update the new TTT(); line in the method to read TTT->new;

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

Sidebar

Related Questions

Recently I have been refactoring some of my C# code and I found a
I've been using Crypto++ with VS2005 and VS2010 for a while now. But recently
Recently, I write a python code to insert HTML text into table. After my
Recently I have read that it makes sense when returning by value from a
I recently received a comment on one of my blog posts about JSLint asking
Recently I came across this Objective-C coding style: - (NSFetchedResultsController *)fetchedResultsController { NSFetchRequest *fetchRequest;
Recently I tried to compile and install ns-2 , a network simulator based on
Recently, I bought a domain name at www.active-domain.com I use it for my home
Recently I splitted an app into two separate ones because I had 15+ models
Recently I have been furthering my knowledge of Javascript, by combining the Processing.js and

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.