New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hash Behaviour differs v5.6.0 to v5.6.1 #4523
Comments
From paul.barry@itcarlow.ieHere's some code: #! /usr/bin/perl -w use strict; use constant HASH_KEY1 => 100; our %hash_desc = ( foreach my $h_desc ( sort keys %hash_desc ) When executed under 5.6.0 the output is: 100 -> This is the hash key one When executed under 5.6.1 the output is: HASH_KEY1 -> This is the hash key one What gives? Why won't hashes in 5.6.1 use constants properly? (Please I'm running on LinuxPPC 2000, with Perl built from downloaded sources Thanks. -- |
From @schwern
5.6.0 was wrong, sorry. A lot of things about 5.6.0 were wrong. $ perl5.4.5 -wle 'use constant FOO => 100; %h = ( FOO => 42 ); print => is documented as follows: The => digraph is mostly just a synonym for the comma operator. It's *Any* word, including one that might also be a constant, is interpreted |
@schwern - Status changed from 'open' to 'resolved' |
From @schwern
Reopening this bug. On second thought, that's not really very obvious from the Patch attached. While I was at it I also added some examples of useful The "=>" operator is a synonym for the comma, but forces any word (con- use constant FOO => "something"; my %h = ( FOO => 23 ); This is equivalent to: my %h = ("FOO", 23); it is NOT: my %h = ("something", 23); If the argument on the left is not a word, it is first interpreted as The "=>" operator is helpful in documenting the correspondence between %hash = ( key => $value ); |
From @schwernperlop.patch--- pod/perlop.pod 2005/07/14 23:48:00 1.1
+++ pod/perlop.pod 2005/07/14 23:54:38
@@ -689,12 +689,29 @@
The C<< => >> operator is a synonym for the comma, but forces any word
(consisting entirely of word characters) to its left to be interpreted
-as a string (as of 5.001). If the argument on the left is not a word,
-it is first interpreted as an expression, and then the string value of
-that is used.
+as a string (as of 5.001). This includes words that might otherwise be
+considered a constant or function call.
+
+ use constant FOO => "something";
+
+ my %h = ( FOO => 23 );
+
+This is equivalent to:
+
+ my %h = ("FOO", 23);
+
+it is I<NOT>:
+
+ my %h = ("something", 23);
+
+If the argument on the left is not a word, it is first interpreted as
+an expression, and then the string value of that is used.
The C<< => >> operator is helpful in documenting the correspondence
between keys and values in hashes, and other paired elements in lists.
+
+ %hash = ( key => $value );
+ login( $username => $password );
=head2 List Operators (Rightward)
|
@schwern - Status changed from 'resolved' to 'open' |
From rick@bort.caOn Thu, Jul 14, 2005 at 04:47:10PM -0700, Michael G Schwern via RT wrote:
Another workaround, since they're constants, is %h = (CONSTANT, 42); -- |
From @steve-m-hayMichael G Schwern via RT wrote:
Thanks. Applied as change 25149 with %hash = ( key => $value ); changed to %hash = ( $key => $value ); (which I think is what you intended given the context.) Radan Computational Ltd. The information contained in this message and any files transmitted with it are confidential and intended for the addressee(s) only. If you have received this message in error or there are any problems, please notify the sender immediately. The unauthorized use, disclosure, copying or alteration of this message is strictly forbidden. Note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Radan Computational Ltd. The recipient(s) of this message should check it and any attached files for viruses: Radan Computational will accept no liability for any damage caused by any virus transmitted by this email. |
From @schwernOn Fri, Jul 15, 2005 at 10:33:36AM +0100, Steve Hay wrote:
Good point. -- |
From @steve-m-hayNow better documented in bleadperl. |
@steve-m-hay - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#7840 (status was 'resolved')
Searchable as RT7840$
The text was updated successfully, but these errors were encountered: