Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Problem with accessing hash Module::CoreList::version with $]

by XooR (Beadle)
on Apr 24, 2009 at 09:43 UTC ( [id://759767]=perlquestion: print w/replies, xml ) Need Help??

XooR has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks, I constructed this simple program that will show what is the problem.
#!/usr/bin/perl use strict; use warnings; use Module::CoreList; use Data::Dumper; print Dumper( $] ); # Prints "5.010000" on my version of perl print Dumper( $Module::CoreList::version{ $] } ); # Prints undef print Dumper( $Module::CoreList::version{ "$]" } ); # Prints undef print Dumper( $Module::CoreList::version{ 5.010000 } ); # Prints "correct" list ...
I don't understand why accessing hash with $] is different from accessing with it's value (in my case 5.010000)?

Replies are listed 'Best First'.
Re: Problem with accessing hash Module::CoreList::version with $]
by betterworld (Curate) on Apr 24, 2009 at 09:57 UTC

    Apparently, this special variable is only a string in perl 5.10, even though the documentation seems to suggest that it be a floating point number. If you use $]+0 in your example, it'll work (which is kind of strange because ordinary hash keys are converted to strings anyway, but in this case I think we are dealing with a tied hash).

    % perl5.8.8 -we 'use Devel::Peek; Dump $]' SV = PVNV(0x9f664d0) at 0x9f63ed0 REFCNT = 1 FLAGS = (NOK,POK,READONLY,pNOK,pPOK) IV = 0 NV = 5.008008 # <-- in 5.8 it was a number PV = 0x9f7d250 "5.008008"\0 CUR = 8 LEN = 12 % perl5.10.0 -we 'use Devel::Peek; Dump $]' SV = PV(0x9457198) at 0x946a610 REFCNT = 1 FLAGS = (POK,READONLY,pPOK) PV = 0x945e538 "5.010000"\0 CUR = 8 LEN = 12
      betterworld sad:
      Apparently, this special variable is only a string in perl 5.10, even though the documentation seems to suggest that it be a floating point number. If you use $]+0 in your example, it'll work (which is kind of strange because ordinary hash keys are converted to strings anyway, but in this case I think we are dealing with a tied hash).
      Thanx, that's solved it. I will read about tied hashes and see if this is a problem.
      Actually that makes no difference, works just fine in 5.10. His problem is he expect Data::Dumper output to be identical. Maybe if he use $Data::Dumper::Sortkeys ... or this
      #!/usr/bin/perl use strict; use warnings; use Module::CoreList; use Data::Dumper; $Data::Dumper::Sortkeys=1; print Dumper( $Module::CoreList::version{ $] }, $Module::CoreList::version{ "$]" }, $Module::CoreList::version{ 5.010000 } ); __END__ $VAR1 = { 'AnyDBM_File' => '1.00', ..... }; $VAR2 = $VAR1; $VAR3 = $VAR1;
Re: Problem with accessing hash Module::CoreList::version with $]
by Anonymous Monk on Apr 24, 2009 at 10:02 UTC
    How are you comparing? Visually? That is a bad idea ;)
    #!/usr/bin/perl use strict; use warnings; use Module::CoreList; print qq{ $Module::CoreList::version{ $] } $Module::CoreList::version{ "$]" } $Module::CoreList::version{ 5.010000 } }; __END__ HASH(0x1a97888) HASH(0x1a97888) HASH(0x1a97888)
    See how they all reference the same hash? They're all the same
    pmvers Module::CoreList 2.17

      If I run your script with 5.8.8, I get the output

      HASH(0x96574a4) HASH(0x96574a4) HASH(0x9628550)

      For 5.10.0, I get

      Use of uninitialized value within %Module::CoreList::version in concat +enation (.) or string at test.pl line 7. Use of uninitialized value in concatenation (.) or string at test.pl l +ine 7. HASH(0x84c82b8)

      Module::CoreList is version 2.15.

      Update: For the 5.10.0 case, Module::CoreList's version is 2.13.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://759767]
Approved by ELISHEVA
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-23 07:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found