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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:25:38+00:00 2026-05-11T18:25:38+00:00

Perl is really good for writing the kind of string/file parsing programs that I

  • 0

Perl is really good for writing the kind of string/file parsing programs that I usually need to do. What I really love is the insignificant amount of time it takes me to write quick scripts and throwaway code, compared to C/C++/JAVA. However, I want to learn how to speed things up.

For example, I would want to learn how to give hints to Perl so that it can make some decisions better—especially things related to strings. It seems to me that Perl copies a string whenever you do anything regardless of whether you really modify the copy later or not. Is this by design (and can I turn that away using some magic?) or am I ranting?

I really want to treat some strings as (const char *). I am sure we always do not need everything to be a std::string with all its baggage involved (let’s assume std::string to be analogous to Perl string). Can I give a hint to Perl to do that on some strings?

I remember reading in some article (please comment if you can place it) that you can hint to Perl that you will not modify some variable and thus it removes the extra baggage that is otherwise required if you were to modify it, etc.

I believe Perl variables have two internal pointers to a same Perl variable—one can store a number and another a string (array of characters). Could I always tell Perl to choose one throughout? Could I make Perl treat some strings as (const char *) so that they do not tag around functionality required to modify them?

For example, I read somewhere (maybe the same article?) that unpack() is faster than substr() because substr() returns a lvalue, so that you can operate on it as well. For example, if I wanted to replace the first two characters of a string with ‘ef’, I could write:

substr(string, 0, 2) = 'ef'; # string now begins with 'ef'

Hence, unless I am using this special feature of substr(), am I better off using substr?

Did I just rant all the way through?

  • 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-11T18:25:38+00:00Added an answer on May 11, 2026 at 6:25 pm

    You can set the SvREADONLY flag on a variable with Readonly::XS, but that does not improve the efficiency. Efficiency comes from choosing the right algorithm, not through compiler hints. If you want your code to be faster/use less memory then profile it (see Devel::NYTProf). When you find a bottleneck either use a different algorithm there or switch to use XS.

    Also, if you are going to try to optimize something, make sure the result really is faster, here is substr vs unpack:

                Rate unpack substr
    unpack 2055647/s     --   -74%
    substr 7989875/s   289%     --
    

    Here is the benchmark code.

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use Benchmark;
    
    my %subs = (
        unpack => sub { return unpack "a3", "foobarbaz" },
        substr => sub { return substr "foobarbaz", 0, 3 }
    );
    
    for my $sub (keys %subs) {
        print "$sub => ", $subs{$sub}(), "\n";
    }
    
    Benchmark::cmpthese -1, \%subs;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a perl script and I would really like to get the amount
I'm pretty new to NLP in general, but getting really good at Perl, and
I have a really crappy file full of unicode bytes that I'm trying to
Okay, so I'm using perl to read in a file that contains some general
I really need help on this. I tried translating this Perl into Python, but
I don't really understand Perl, so I was wondering if someone could give me
I have never used Perl, but I am really impressed by the ack ,
This is a really basic issue, but I'm new to perl and cannot work
I've been working a lot lately with perl, still I dont really know how
I'm looking for good timer implementation in perl. The situation I met is like:

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.