I have decimal numbers as hash keys. These numbers are coming from a text stored in $title and parsed by a REGEX. It works, unless there is a 0 on last decimal position.
The file test.txt contains a title (one per line) (see table below - $title)
%ifac= ( 14.152 => "JCI", 9.334 => "JHEP", 5.745 => "JIMM", 6.270 => "JID", 1.480 => "JRN", 6.105 => "KI" ); open (FH, "<test.txt"); my $zler=0; while(defined(my $title=<FH>)) { if ($title=~m|.{10,}\(IF ([\.\d]+)\)|) { $id=$zler; $factor=$1; $jour=$ifac{$factor}; print "INSERT INTO table (id, key, value) VALUES ($id,'ifac','$jou +r');\n"; } $zler++; } close(FH);
Result of $title, $factor, $jour would be for example:
| $title | $factor | $jour (expected) | $jour (as it is) |
|---|---|---|---|
| 1. This is a test. (IF 6.270) | 6.270 | JID | undef |
| 2. Another test, working and resulting in JHEP. (IF 9.334) | 9.334 | JHEP | JHEP |
| 3. Last test, which does not work. (IF 1.480) | 1.480 | JRN | undef |
If $factor results in 6.270 or 1.480 then $jour is undefined but should result in JID or JRN.
I tried a direct access to the hash with
$jour= $ifac{6.270} $jour= $ifac{6.27} $jour= $ifac{"6.270"}
In these cases $jour results in JID (except for the "6.270" undefined (this is OK, as the hash key is a number and not a string)
What is the difference between the direct access and access of hash key via the variable $ifac{$factor}? It seems that the last 0 is the problem. But in direct access it would work, even if I leave out the last 0.
Regards, Alex
In reply to decimal numbers as hash keys by Alex31
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |