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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:54:23+00:00 2026-05-11T03:54:23+00:00

I’ve just started to learn about tie . I have a class named Link

  • 0

I’ve just started to learn about tie. I have a class named Link which I would like to do the following thing:

  • if fetched, return the link’s address
  • if stored, store the new address
  • be able to call methods on it

So far, my code is :

 package Link;  sub FETCH {     my $this = shift;     return $this->{'site'}; }  sub STORE {     my ($self,$site) = @_;     $self->{'site'}   = $site; }  sub print_method {     my $self = shift;     print $self->{'site'}; }  sub TIESCALAR {     my $class = shift;     my $link  = shift;     my $this  = {};     bless($this,$class);     $this->{'site'} = $link;     return $this; }  1; 

And the code I’m using to check the functionality is:

 use Link;  tie my $var,'Link','http://somesite.com'; $var->print_method; 

When ran, the script will terminate with the following error: Can’t call method ‘print_method’ without a package or object reference at tietest.pl line 4..

If I understand its message correctly, $var->print_method resolves to some string upon which the method print_method is called. How could I benefit from tie, but also use the variable as an object?

EDIT: after experimenting a bit,I found out that if I return $self on fetch , I can call the methods , however , fetch won’t return the address .

EDIT 2:the perl monks supplied me the solution : tied . tied will return a reference to the object VARIABLE .

By combining tied with my methods , I can accomplish everything I wanted .

  • 1 1 Answer
  • 3 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. 2026-05-11T03:54:24+00:00Added an answer on May 11, 2026 at 3:54 am

    Tie is the wrong tool for this job. You use ties when you want the same interface as normal data types but want to customize how the operations do their work. Since you want to access and store a string just like a scalar already does, tie doesn’t do anything for you.

    It looks like you want the URI module, or a subclass of it, and perhaps some overloading.

    If you really need to do this, you need to use the right variable. The tie hooks up the variable you specify to the class you specify, but it’s still a normal scalar (and not a reference). You have to use the object it returns if you want to call methods:

    my $secret_object = tie my($normal_scalar), 'Tie::Class', @args; $secret_object->print_method; 

    You can also get the secret object if you only have the tied scalar:

    my $secret_object = tied $normal_scalar; 

    I have an entire chapter on tie in Mastering Perl.

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

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer All your errors stem from the fact that you incorrectly… May 12, 2026 at 1:12 am
  • Editorial Team
    Editorial Team added an answer Row-major order versus column-major order. Recall first that all multi-dimensional… May 12, 2026 at 1:12 am
  • Editorial Team
    Editorial Team added an answer I'm running Vista Home Premium x64 SP2 and can see… May 12, 2026 at 1:12 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.