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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:53:18+00:00 2026-05-23T15:53:18+00:00

There is automatic conversion between numbers and strings in Perl. From the Llama book:

  • 0

There is automatic conversion between numbers and strings in Perl.

From the Llama book:

You don’t need to worry about the
difference between numbers and
strings; just use the proper
operators, and Perl will make it all
work.

And if you’re worried about
efficiency, don’t be. Perl generally
remembers the result of a conversion
so that it’s done only once.

How does this happens? I mean how does Perl remembers it and for how much time?

Doesn’t it affect the efficiency even by a single bit?

  • 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-23T15:53:19+00:00Added an answer on May 23, 2026 at 3:53 pm

    Why should the efficiency be slower?

    If you do the conversion automatically or manually, it is absolutely the same. But by doing it automatically you just need to type less code.

    A scalar variable in perl can hold many different values. The runtime (perl interpreter) does a conversion and saves the number inside the scalar.

    You can see such internal things with Devel::Peek

    #!/usr/bin/env perl
    use Devel::Peek;
    
    my $value = '15';
    Dump($value);
    $value + 5;
    Dump($value);
    $value = 5;
    Dump($value);
    

    Output:

    SV = PV(0x8f71040) at 0x8f82d88
      REFCNT = 1
      FLAGS = (PADMY,POK,pPOK)
      PV = 0x8f7ecb8 "15"\0
      CUR = 2
      LEN = 4
    SV = PVIV(0x8f7a2fc) at 0x8f82d88
      REFCNT = 1
      FLAGS = (PADMY,IOK,POK,pIOK,pPOK)
      IV = 15
      PV = 0x8f7ecb8 "15"\0
      CUR = 2
      LEN = 4
    SV = PVIV(0x8f7a2fc) at 0x8f82d88
      REFCNT = 1
      FLAGS = (PADMY,IOK,pIOK)
      IV = 5
      PV = 0x8f7ecb8 "15"\0
      CUR = 2
      LEN = 4
    

    Here you can see that a Scalar Value (SV) has "15" the string as (PV), after doing an addition it adds (IV) (Integer Value).

    A scalar contains a flags to know which value is correct. In the first dump you see the Flag POK that says PV is a correct current value. If you ask for this value, perl can immediately return this value.

    After the addition you see “IOK” that says “IV” value is also okay. Actually the variable itself was not changed, but because an addition with a string was made perl needed todo a conversation from string to an int. What you see after the addition is that POK and IOK are valid. That means the Scalar currently holds a valid string and a valid Integer. As long as the variable doesn’t change, both values are valid, and perl don’t need to do a conversation.

    But after changing the value to the integer 5 you see that “POK” is not set anymore. This operation sets the IV to a new value and invalidates the PV value. As long as you just work with $value as an integer nothing additional will happen. As soon as you use $value within a string context will will do a conversion to a string and will update PV and sets POK. But only has to do that once.

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

Sidebar

Related Questions

Are there automatic ways to sync comments between an interface and its implementation? I'm
Is there an automatic way in SQL Server 2005 to create a database from
I am wondering if there is something like automatic conversion/wrapper code generation of a
Is there a way to use an org-mode table to do automatic unit conversion?
Are there any automatic methods for trimming a path string in .NET? For example:
Is there an automatic way to add base classes to Linq2Sql entities? I know
Is there an automatic way I can use to rename a pylons controller? If
This is a simple question : Is there any automatic indentation alignment on Eclipse
When plotting a graph with a discontinuity/asymptote/singularity/whatever, is there any automatic way to prevent
I wonder whether there is any automatic way of determining (at least roughly) the

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.