nif has asked for the wisdom of the Perl Monks concerning the following question:
... After only 3 hours searching, finally found a mistake in my code ...
I am somewhat disappointed actually getting no warnings from the compiler - please consider the following code:And here is the output#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash; $hash{'A'.'B'} = 1; # note a mistakenly written comma between 'C' and 'D' $hash{'C','D'} = 2; $hash{'E','F'} = 3; print Dumper(\%hash); print exists $hash{'CD'} ? "YES\n" : "NO\n";
My xterm shows nothing between C and D in the output from Dumper, but with hexdump i could see that there is actually HEX: '1c' there$VAR1 = { 'CD' => 2, 'EF' => 3, 'AB' => 1 }; NO
Any ideas, what's really happened? Why is it '1c' and not 'f5'? Is it a bug that perl produces no warnings in this case?24 56 41 52 31 20 3d 20 7b 0a 20 20 20 20 20 20 |$VAR1 = {. | 20 20 20 20 27 43 1c 44 27 20 3d 3e 20 32 2c 0a | 'C.D' => 2,.| 20 20 20 20 20 20 20 20 20 20 27 45 1c 46 27 20 | 'E.F' | 3d 3e 20 33 2c 0a 20 20 20 20 20 20 20 20 20 20 |=> 3,. | 27 41 42 27 20 3d 3e 20 31 0a 20 20 20 20 20 20 |'AB' => 1. | 20 20 7d 3b 0a 4e 4f 0a | };.NO.|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Comma Operator, BUG or feature ???
by moritz (Cardinal) on Sep 22, 2009 at 15:35 UTC | |
by nif (Sexton) on Sep 22, 2009 at 16:21 UTC | |
|
Re: Comma Operator, BUG or feature ???
by ikegami (Patriarch) on Sep 22, 2009 at 16:01 UTC | |
|
Re: Comma Operator, BUG or feature ???
by JavaFan (Canon) on Sep 22, 2009 at 17:13 UTC |