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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:24:13+00:00 2026-05-23T22:24:13+00:00

I have to admit, this one has me foxed. Consider this code: use version;

  • 0

I have to admit, this one has me foxed.

Consider this code:

use version;
use Data::Dumper;
my $codeLevel = q{6.1.0.7 (build 25.3.1103030000)};
print STDERR qq{$codeLevel\n};
my $vrmf;
if($codeLevel =~ /^\s*([0-9.]*) \(build.*\)/) { 
    print STDERR "$1\n";
    $vrmf = version->parse($1);
}

print STDERR Dumper($vrmf);

The output, as expected, is:

6.1.0.7 (build 25.3.1103030000)
6.1.0.7
$VAR1 = bless( {
                 'original' => '6.1.0.7',
                 'qv' => 1,
                 'version' => [
                                6,
                                1,
                                0,
                                7
                              ]
               }, 'version' );

However, remove the second print:

use version;
use Data::Dumper;
my $codeLevel = q{6.1.0.7 (build 25.3.1103030000)};
print STDERR qq{$codeLevel\n};
my $vrmf;
if($codeLevel =~ /^\s*([0-9.]*) \(build.*\)/) {
    $vrmf = version->parse($1);
}
print STDERR Dumper($vrmf);

The output becomes:

6.1.0.7 (build 25.3.1103030000)
$VAR1 = bless( {
                 'original' => '0',
                 'version' => [
                                0
                              ]
               }, 'version' );

I can’t find any documentation that says that print can affect variables passed to it, or that it affects the regex matching variables.

Can someone explain to me what is happening here, please?

  • 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-23T22:24:13+00:00Added an answer on May 23, 2026 at 10:24 pm

    Scalar values in Perl can be a number and a string at the same time. An SV object (SV = Scalar Value) has slots for integer, float, and string values and flags identifying which of those values are valid at any point in time. When you use a value as a string perl calculates the string value and sets a flag identifying it as valid. (Other operations, like adding 1 would invalidate the string value.) When you print something you’re (unsurprisingly) using it as a string. You can see this using Devel::Peek.

    use Devel::Peek;
    
    my $s = '6.1.0.7 (build 25.3.1103030000)';
    if ($s =~ /^\s*([0-9.]*) \(build.*\)/) { 
        Dump($1);
        printf STDERR "\$1 = $1\n";
        Dump($1);
    }
    

    The result is

    SV = PVMG(0x1434ca4) at 0x144d83c
      REFCNT = 1
      FLAGS = (GMG,SMG)
      IV = 0
      NV = 0
      PV = 0
      MAGIC = 0x146c324
        MG_VIRTUAL = &PL_vtbl_sv
        MG_TYPE = PERL_MAGIC_sv(\0)
        MG_OBJ = 0x144d82c
        MG_LEN = 1
        MG_PTR = 0x14631c4 "1"
    $1 = 6.1.0.7
    SV = PVMG(0x1434ca4) at 0x144d83c
      REFCNT = 1
      FLAGS = (GMG,SMG,pPOK)
      IV = 0
      NV = 0
      PV = 0x1487a1c "6.1.0.7"\0
      CUR = 7
      LEN = 8
      MAGIC = 0x146c324
        MG_VIRTUAL = &PL_vtbl_sv
        MG_TYPE = PERL_MAGIC_sv(\0)
        MG_OBJ = 0x144d82c
        MG_LEN = 1
        MG_PTR = 0x14631c4 "1"
    

    Note that in the second dump output the PV slot (string value) has been populated and the pPOK flag has been added under FLAGS.

    So, yes, print has side-effects of a sort although under normal circumstances you should never notice. version->parse() appears to expect a string argument but isn’t triggering string semantics. Given that version prefers to use an XS implementation, it’s probably a bug there rather than in perl. Note that making a copy of the capture data causes the problem to disappear:

    use Data::Dump qw'pp';
    
    my $s = '6.1.0.7 (build 25.3.1103030000)';
    if ($s =~ /^\s*([0-9.]*) \(build.*\)/) { 
        my $x = $1;
        pp(version->parse($x));
    }
    

    Result:

    bless({ original => "6.1.0.7", qv => 1, version => [6, 1, 0, 7] }, "version")
    
    • 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.