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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:16:37+00:00 2026-05-20T10:16:37+00:00

In the documentation for the CPAN module DateTime I found the following: Once you

  • 0

In the documentation for the CPAN module DateTime I found the following:

Once you set the formatter, the
overloaded stringification method will
use the formatter.

It seems there is some Perl concept called “stringification” that I somehow missed. Googling has not clarified it much. What is this “stringification”?

  • 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-20T10:16:37+00:00Added an answer on May 20, 2026 at 10:16 am

    “stringification” happens any time that perl needs to convert a value into a string. This could be to print it, to concatenate it with another string, to apply a regex to it, or to use any of the other string manipulation functions in Perl.

    say $obj;
    say "object is: $obj";
    if ($obj =~ /xyz/) {...}
    say join ', ' => $obj, $obj2, $obj3;
    if (length $obj > 10) {...}
    $hash{$obj}++;
    ...
    

    Normally, objects will stringify to something like Some::Package=HASH(0x467fbc) where perl is printing the package it is blessed into, and the type and address of the reference.

    Some modules choose to override this behavior. In Perl, this is done with the overload pragma. Here is an example of an object that when stringified produces its sum:

    {package Sum;
        use List::Util ();
    
        sub new {my $class = shift; bless [@_] => $class}
    
        use overload fallback => 1,
            '""' => sub {List::Util::sum @{$_[0]}}; 
    
        sub add {push @{$_[0]}, @_[1 .. $#_]}
    }
    
    my $sum = Sum->new(1 .. 10);
    
    say ref $sum; # prints 'Sum'
    say $sum;     # prints '55'
    $sum->add(100, 1000);
    say $sum;     # prints '1155'
    

    There are several other ifications that overload lets you define:

    'bool' Boolification    The value in boolean context   `if ($obj) {...}`
    '""'   Stringification  The value in string context    `say $obj; length $obj`
    '0+'   Numification     The value in numeric context   `say $obj + 1;`
    'qr'   Regexification   The value when used as a regex `if ($str =~ /$obj/)`
    

    Objects can even behave as different types:

    '${}'   Scalarification   The value as a scalar ref `say $$obj`
    '@{}'   Arrayification    The value as an array ref `say for @$obj;`
    '%{}'   Hashification     The value as a hash ref   `say for keys %$obj;`
    '&{}'   Codeification     The value as a code ref   `say $obj->(1, 2, 3);`
    '*{}'   Globification     The value as a glob ref   `say *$obj;`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.