Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Building a hash from file and getting wrong result.

by flexvault (Monsignor)
on May 15, 2017 at 20:11 UTC ( [id://1190342]=perlquestion: print w/replies, xml ) Need Help??

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

Dear Monks,

I've come across a problem while doing some Perl system maintenance, and the problem exists in both 5.14.2 and the lastest Perl(5.24.1) from CPAN.org. I'm saying a "problem" but it's so basic, I must be causing the *problem*. The below code is a reduced script showing the problem. Data is at the end of script. see below.

#!/usr/local/bin/pyrperl -w use strict; use warnings; use Fcntl qw( :DEFAULT :flock SEEK_SET ); our ( $ROOT, $Debug, $LOCK ); $ROOT = `pwd`; chomp ( $ROOT ); if ( substr($ROOT,-1) eq "/" ) { chop( $ROOT ); } $Debug = 4; my $WRKLock = "$ROOT/lock"; open ( $LOCK, ">>","$WRKLock") || die " ! open-20 |$WRKLock| $!\n" +; my $ret = &Build_Orders_Lists(); exit; sub Build_Orders_Lists { our ( $ROOT, $Debug, $LOCK ); my %SeqOrders = (); my $allcases = "$ROOT/indata"; my $mycases = "$ROOT/outdata"; my $no = 1; { # open ( my $in,"<",$allcases ) || die " ! open-900 |$allca +ses| $!\n"; open ( my $out,">",$mycases ) || die " ! open-901 |$mycase +s| $!\n"; open ( my $nxout,">","$ROOT/log1" ) || die " ! open-901 |$ +mycases| $!\n"; open ( my $xxout,">","$ROOT/log2" ) || die " ! open-901 |$ +mycases| $!\n"; if ( flock( $LOCK, LOCK_SH ) ) { %SeqOrders = (); $no = 1; while( my $input = <DATA> ) { if ( substr( $input, 0, 2 ) eq '99' ) { last; } print $nxout $input; chomp( $input ); my @Info = split("\t",$input); my $recid = $Info[2]; substr( $recid, 0, 1, '' ); $recid .= substr( $Info[2], 0, 1 ); $SeqOrders{ $recid } = $input; print $xxout "$no:$recid\t$SeqOrders{ $recid }\n"; $no++; } } if ( flock( $out, LOCK_EX ) ) { $no = 1; open ( my $yyout,">","$ROOT/log3" ) || die " ! open-90 +1 |$mycases| $!\n"; foreach my $recid ( reverse sort %SeqOrders ) { if ( ! defined $SeqOrders{ $recid } ) { $SeqOrder +s{ $recid } = ''; } print $out "$recid:$SeqOrders{ $recid }\n"; print $yyout "||$recid||$SeqOrders{ $recid }\n"; } } close $out; } } 1; __DATA__ US 2017-04-25 P17-115-00043-P 2017-04-25 Accepted XXX + 2017-00916-UD-NJC Information 4714336 240.00 5.00 + 8.40 10065 20 16: +28:26.162-07:00 US 2017-04-25 P17-115-00046-P 2017-04-25 Accepted XXX + 2017-00916-OR-CJC Information 3538098 225.00 5.00 + 7.88 10249 20 16: +43:14.310-07:00 US 2017-04-25 P17-115-00048-P 2017-04-25 Accepted XXX + 2017-00916-OR-CJC Information 2549853 225.00 5.00 + 7.88 10249 20 17: +20:07.354-07:00 US 2017-04-25 P17-115-00049-P 2017-04-25 Accepted XXX + 2017-00916-UD-CJC Information 2549860 240.00 5.00 + 8.40 10065 20 17: +22:00.419-07:00 US 2017-04-26 E17-109-00010-P 2017-04-19 Accepted XXX + 2009-00246-UD-HNB Information 1380135 50.00 5.00 + 1.75 10378 20 08:0 +1:04.027-07:00 US 2017-04-26 P17-115-00050-P 2017-04-25 Accepted XXX + 2017-00916-UD-NJC Information 2549859 240.00 5.00 + 8.40 10249 20 08: +02:45.472-07:00 US 2017-04-26 E17-115-00054-P 2017-04-25 Partial XXX + 2017-00914-UD-CJC Information 3538184 25.00 5.00 + 0.88 10065 20 08:18 +:22.493-07:00 US 2017-04-26 P17-115-00051-P 2017-04-25 Accepted XXX + 2017-00916-UD-NJC Information 1381341 240.00 5.00 + 8.40 10065 20 08: +20:20.321-07:00 US 2017-04-26 P17-115-00052-P 2017-04-25 Accepted XXX + 2017-00916-UD-HNB Information 4714480 240.00 5.00 + 8.40 10065 20 08: +31:31.958-07:00 US 2017-04-26 E17-109-00017-P 2017-04-19 Accepted XXX + 2015-00824-UD-HNB Information 4711172 25.00 5.00 + 0.88 10378 20 08:4 +0:49.988-07:00 US 2017-04-26 E17-115-00056-P 2017-04-25 Accepted XXX + 2017-00915-UD-NJC Information 2549876 20.00 5.00 + 0.70 10127 20 08:4 +1:36.325-07:00 US 2017-04-26 E17-115-00055-P 2017-04-25 Partial XXX + 2017-00914-UD-CJC Information 3538188 25.00 5.00 + 0.88 10065 20 08:45 +:49.402-07:00 US 2017-04-26 E17-109-00029-P 2017-04-19 Accepted XXX + 2008-00207-UD-HNB Information 4711229 25.00 5.00 + 0.88 10378 20 08:5 +2:51.499-07:00 US 2017-04-26 E17-116-00003-P 2017-04-26 Accepted XXX + 99999999 Information 2549914 5.00 0.00 +10546 20 09:00:09.227-07:00 US 2017-04-26 E17-109-00021-P 2017-04-19 Accepted XXX + 2016-00873-UD-HNB Information 4711185 25.00 5.00 + 0.88 10378 20 09:0 +5:43.932-07:00 US 2017-04-26 E17-109-00031-P 2017-04-19 Accepted XXX + 2011-00492-UD-HNB Information 3535722 25.00 5.00 + 0.88 10378 20 09:0 +8:20.122-07:00 US 2017-04-26 P17-116-00005-P 2017-04-26 Accepted XXX + 2017-00916-UD-NJC Information 2549916 240.00 5.00 + 8.40 10127 20 09: +09:28.757-07:00 US 2017-04-26 E17-109-00023-P 2017-04-19 Accepted XXX + 2015-00803-UD-HNB Information 3535675 25.00 5.00 + 0.88 10378 20 09:0 +9:45.021-07:00 US 2017-04-26 E17-109-00032-P 2017-04-19 Accepted XXX + 2014-00743-UD-HNB Information 4711242 25.00 5.00 + 0.88 10378 20 09:2 +2:13.178-07:00 US 2017-04-26 P17-116-00009-P 2017-04-26 Accepted XXX + 2017-00916-UD-HNB Information 3538273 240.00 9.00 + 8.40 10135 20 10: +18:35.775-07:00 US 2017-04-26 E17-116-00008-P 2017-04-26 Accepted XXX + 2016-00889-BC-CJC Information 4714644 5.00 + 0.00 10546 20 10:18:46. +718-07:00 US 2017-04-26 E17-115-00023-P 2017-04-25 Accepted XXX + 2016-00890-CL-CJC Information 1381221 20.00 + 0.00 10658 20 10:19:46 +.251-07:00 US 2017-04-26 E17-115-00047-P 2017-04-25 Accepted XXX + 2017-00915-UD-CJC Information 3538114 5.00 + 0.00 10249 20 10:22:32. +555-07:00 US 2017-04-26 E17-115-00019-P 2017-04-25 Accepted XXX + 2015-00797-FR-CJC Information 1381188 5.00 + 0.00 10546 20 10:30:46. +680-07:00 US 2017-04-26 E17-115-00044-P 2017-04-25 Accepted XXX + 2017-00914-UD-HNB Information 3538029 20.00 5.00 + 0.70 10127 20 10:4 +0:08.634-07:00 US 2017-04-26 E17-115-00039-P 2017-04-25 Partial XXX + 2016-00871-BC-CJC Information 3538000 5.00 +0.00 10127 20 11:07:32.9 +86-07:00 US 2017-04-26 E17-110-00002-P 2017-04-20 Accepted XXX + 99999999 Information 4711724 25.00 9.00 0.8 +8 10137 20 11:34:57.832- +07:00 US 2017-04-26 E17-116-00001-P 2017-04-26 Accepted XXX + 99999999 Information 4714609 60.00 5.00 2.1 +0 10546 20 12:27:53.349- +07:00 US 2017-04-26 P17-116-00014-P 2017-04-26 Accepted XXX + 2017-00916-UD-NJC Information 3538379 240.00 5.00 + 8.40 10249 20 12: +43:02.694-07:00 US 2017-04-26 E17-116-00018-P 2017-04-26 Accepted XXX + 2017-00913-UD-NJC Information 4714878 60.00 5.00 + 2.10 10127 20 13:1 +9:57.294-07:00 US 2017-04-26 P17-116-00017-P 2017-04-26 Accepted XXX + 2017-00916-UD-NJC Information 4714875 240.00 5.00 + 8.40 10065 20 13: +31:26.197-07:00 US 2017-04-26 E17-116-00010-P 2017-04-26 Accepted XXX + 2017-00914-UD-CJC Information 2549946 5.00 + 0.00 10127 20 13:47:41. +376-07:00 US 2017-04-26 E17-114-00002-P 2017-04-24 Accepted XXX + 2016-00890-BT-CJC Information 4713202 9.00 + 0.00 10099 20 13:47:57. +936-07:00 US 2017-04-26 E17-115-00031-P 2017-04-25 Accepted XXX + 2017-00909-UD-NJC Information 4714240 25.00 5.00 + 0.88 10249 20 13:5 +1:05.770-07:00 US 2017-04-26 E17-116-00012-P 2017-04-26 Accepted XXX + 2017-00915-UD-CJC Information 1381378 5.00 + 0.00 10127 20 13:52:42. +682-07:00 US 2017-04-26 P17-116-00015-P 2017-04-26 Accepted XXX + 2017-00916-UD-CJC Information 2550059 240.00 5.00 + 8.40 10127 20 13: +54:13.356-07:00 US 2017-04-26 P17-116-00022-P 2017-04-26 Accepted XXX + 2017-00916-UD-NJC Information 1381474 240.00 5.00 + 8.40 10127 20 14: +37:06.541-07:00 US 2017-04-26 E17-116-00025-P 2017-04-26 Accepted XXX + 2016-00894-UD-HNB Information 4714954 5.00 + 0.00 10065 20 15:04:41. +454-07:00 US 2017-04-26 E17-116-00007-P 2017-04-26 Accepted XXX + 99999999 Information 2549917 25.00 5.00 0.8 +8 10546 20 15:14:50.089- +07:00 US 2017-04-26 E17-116-00013-P 2017-04-26 Accepted XXX + 2017-00913-UD-CJC Information 4714690 25.00 5.00 + 0.88 10127 20 15:1 +8:13.048-07:00 US 2017-04-26 E17-116-00030-P 2017-04-26 Accepted XXX + 2017-00916-UD-NJC Information 2550176 5.00 + 0.00 10065 20 16:08:30. +582-07:00 US 2017-04-26 P17-116-00032-P 2017-04-26 Rejected XXX + 99999999 Information 2550210 5.00 0.00 +10127 20 16:47:09.818-07:00 US 2017-04-27 E17-116-00029-P 2017-04-26 Accepted XXX + 2008-00048-UD-NJC Information 1381512 25.00 9.00 + 0.88 10137 20 08:0 +0:56.231-07:00 US 2017-04-27 E17-116-00031-P 2017-04-26 Accepted XXX + 2017-00910-UD-HNB Information 3538615 5.00 + 0.00 10065 20 08:47:08. +928-07:00 US 2017-04-27 E17-116-00026-P 2017-04-26 Accepted XXX + 2017-00915-UD-HNB Information 2550159 20.00 5.00 + 0.70 10065 20 09:1 +6:35.514-07:00 US 2017-04-27 E17-116-00034-P 2017-04-26 Accepted XXX + 2017-00915-UD-HNB Information 4715140 20.00 5.00 + 0.70 10065 20 09:3 +2:03.932-07:00 US 2017-04-27 E17-116-00024-P 2017-04-26 Accepted XXX + 2016-00871-BC-CJC Information 4714945 5.00 + 0.00 10127 20 09:36:41. +675-07:00 US 2017-04-27 P17-117-00001-P 2017-04-27 Accepted XXX + 2017-00916-BC-CJC Information 2550260 225.00 5.00 + 7.88 10546 20 09: +37:02.958-07:00 US 2017-04-27 E17-116-00033-P 2017-04-26 Accepted XXX + 2017-00915-UD-HNB Information 1381546 5.00 + 0.00 10065 20 09:41:44. +423-07:00 US 2017-04-27 E17-111-00039-P 2017-04-21 Accepted XXX + 2015-00820-UD-HNB Information 1380776 25.00 5.00 + 0.88 10065 20 09:5 +9:50.377-07:00 US 2017-04-27 E17-117-00005-P 2017-04-27 Accepted XXX + 99999999 Information 1381573 5.00 0.00 +10546 20 10:00:51.999-07:00 US 2017-04-27 P17-117-00002-P 2017-04-27 Accepted XXX + 2017-00916-UD-HNB Information 4715341 385.00 5.00 + 13.48 10127 20 10: +06:54.768-07:00 US 2017-04-27 E17-114-00027-P 2017-04-24 Accepted XXX + 2017-00911-UD-CJC Information 3537332 9.00 + 0.00 10065 20 10:48:27. +908-07:00 US 2017-04-27 E17-117-00007-P 2017-04-27 Accepted XXX + 2017-00903-BC-CJC Information 1381585 5.00 + 0.00 10546 20 10:50:06. +205-07:00 US 2017-04-27 E17-117-00012-P 2017-04-27 Accepted XXX + 2017-00913-UD-HNB Information 3538833 5.00 + 0.00 10249 20 11:29:21. +048-07:00 US 2017-04-27 E17-117-00013-P 2017-04-27 Partial XXX + 2017-00912-UD-NJC Information 1381615 25.00 5.00 + 0.88 10065 20 11:32 +:34.441-07:00 US 2017-04-27 E17-115-00003-P 2017-04-25 Accepted XXX + 2017-00901-BT-CJC Information 4713928 870.00 5.00 + 30.45 10127 20 11: +37:22.418-07:00 US 2017-04-27 P17-117-00017-P 2017-04-27 Accepted XXX + 2017-00917-UD-HNB Information 1381638 240.00 5.00 + 8.40 10127 20 11: +59:37.051-07:00 US 2017-04-27 E17-117-00019-P 2017-04-27 Accepted XXX + 2017-00910-PT-CJC Information 4715478 9.00 + 0.00 10549 20 12:01:42. +403-07:00 US 2017-04-27 P17-117-00021-P 2017-04-27 Accepted XXX + 2017-00917-UD-NJC Information 4715519 240.00 5.00 + 8.40 10127 20 12: +28:41.732-07:00 US 2017-04-27 E17-117-00026-P 2017-04-27 Rejected XXX + 2016-00891-OR-CJC Information 4715565 9.00 + 0.00 10622 20 13:53:03. +215-07:00 US 2017-04-27 P17-117-00015-P 2017-04-27 Accepted XXX + 2017-00917-UD-HNB Information 2550408 240.00 5.00 + 8.40 10249 20 14: +02:53.945-07:00 US 2017-04-27 E17-117-00027-P 2017-04-27 Accepted XXX + 99999999 Information 4715591 30.00 9.00 1.0 +5 10137 20 14:16:50.698- +07:00 US 2017-04-27 E17-117-00028-P 2017-04-27 Accepted XXX + 99999999 Information 4715595 30.00 9.00 1.0 +5 10137 20 14:24:32.446- +07:00 US 2017-04-27 P17-117-00030-P 2017-04-27 Accepted XXX + 2017-00917-UD-HNB Information 4715626 240.00 5.00 + 8.40 10065 20 14: +39:33.961-07:00 US 2017-04-27 P17-117-00031-P 2017-04-27 Accepted XXX + 2017-00917-UD-HNB Information 2550470 240.00 5.00 + 8.40 10065 20 14: +48:09.581-07:00 US 2017-04-27 E17-108-00046-P 2017-04-18 Accepted XXX + 2016-00881-UD-CJC Information 4710806 25.00 9.00 + 0.88 10679 20 15:1 +4:16.318-07:00 US 2017-04-27 E17-116-00023-P 2017-04-26 Accepted XXX + 2008-00217-UD-HNB Information 4714918 25.00 9.00 + 0.88 10137 20 15:2 +1:17.036-07:00 US 2017-04-27 E17-117-00032-P 2017-04-27 Rejected XXX + 2017-00907-UD-CJC Information 3539028 5.00 + 0.00 10127 20 15:24:08. +760-07:00 US 2017-04-27 E17-117-00035-P 2017-04-27 Accepted XXX + 2016-00853-CO-CJC Information 3539079 20.00 + 0.00 10469 20 16:17:23 +.604-07:00 US 2017-04-28 E17-116-00021-P 2017-04-26 Partial XXX + 2017-00910-UD-CJC Information 4714894 25.00 5.00 + 0.88 10065 20 07:32 +:03.518-07:00 US 2017-04-28 E17-115-00002-P 2017-04-25 Accepted XXX + 99999999 Information 3537689 25.00 9.00 0.8 +8 10137 20 08:16:54.048- +07:00 US 2017-04-28 P17-117-00043-P 2017-04-27 Accepted XXX + 2017-00917-UD-CJC Information 3539205 240.00 5.00 + 8.40 10065 20 08: +17:00.068-07:00 US 2017-04-28 E17-117-00038-P 2017-04-27 Accepted XXX + 2016-00891-OR-CJC Information 4715786 9.00 + 0.00 10622 20 08:17:41. +498-07:00 US 2017-04-28 E17-117-00042-P 2017-04-27 Accepted XXX + 2017-00915-UD-HNB Information 4715852 5.00 + 0.00 10065 20 08:35:52. +284-07:00 US 2017-04-28 E17-116-00025-2P 2017-04-26 Rejected XXX + 2016-00894-UD-HNB Information 4714953 5.00 + 0.00 10065 20 08:58:42 +.801-07:00 US 2017-04-28 E17-117-00036-P 2017-04-27 Accepted XXX + 99999999 Information 2550511 30.00 9.00 1.0 +5 10137 20 09:17:40.569- +07:00 US 2017-04-28 E17-117-00004-P 2017-04-27 Accepted XXX + 99999999 Information 1381569 60.00 5.00 2.1 +0 10546 20 09:46:10.238- +07:00 US 2017-04-28 E17-118-00003-P 2017-04-28 Accepted XXX + 2017-00914-UD-HNB Information 2550657 5.00 + 0.00 10127 20 10:12:01. +584-07:00 US 2017-04-28 E17-117-00033-P 2017-04-27 Rejected XXX + 2017-00904-UD-CJC Information 1381734 5.00 + 0.00 10127 20 10:17:01. +796-07:00 US 2017-04-28 E17-117-00037-P 2017-04-27 Rejected XXX + 2017-00907-UD-CJC Information 4715773 5.00 + 0.00 10127 20 10:19:17. +739-07:00 US 2017-04-28 E17-118-00006-P 2017-04-28 Accepted XXX + 99999999 Information 1381874 9.00 0.00 +10137 20 10:32:30.324-07:00 US 2017-04-28 E17-118-00026-P 2017-04-28 Accepted XXX + 2017-00915-UD-HNB Information 4716270 5.00 + 0.00 10065 20 15:37:03. +802-07:00 US 2017-04-28 E17-117-00045-P 2017-04-27 Accepted XXX + 2017-00916-UD-CJC Information 3539222 20.00 5.00 + 0.70 10127 20 15:5 +8:07.547-07:00 US 2017-04-28 E17-117-00022-P 2017-04-27 Partial XXX + 2008-00059-BC-CJC Information 4715546 4.95 +0.00 10230 20 16:00:23.5 +31-07:00 US 2017-04-28 E17-118-00004-P 2017-04-28 Accepted XXX + 2017-00915-UD-HNB Information 2550675 5.00 + 0.00 10127 20 16:01:53. +797-07:00 US 2017-04-28 P17-118-00014-P 2017-04-28 Accepted XXX + 2017-00917-UD-CJC Information 3539427 240.00 5.00 + 8.40 10127 20 16: +12:46.567-07:00 US 2017-04-28 E17-118-00005-P 2017-04-28 Accepted XXX + 2017-00916-UD-CJC Information 2550681 5.00 + 0.00 10127 20 16:15:41. +084-07:00 US 2017-04-28 P17-118-00016-P 2017-04-28 Accepted XXX + 2017-00917-UD-CJC Information 1381915 240.00 5.00 + 8.40 10127 20 16: +27:30.079-07:00 US 2017-04-28 E17-117-00034-P 2017-04-27 Accepted XXX + 2017-00910-UD-CJC Information 2550482 25.00 5.00 + 0.88 10127 20 16:2 +7:39.834-07:00 US 2017-04-28 P17-118-00023-P 2017-04-28 Accepted XXX + 2017-00917-UD-CJC Information 3539463 240.00 5.00 + 8.40 10249 20 16: +45:44.015-07:00 US 2017-04-28 E17-118-00027-P 2017-04-28 Accepted XXX + 2017-00915-UD-HNB Information 4716282 5.00 + 0.00 10065 20 17:01:24. +588-07:00 US 2017-04-28 E17-118-00025-P 2017-04-28 Accepted XXX + 2017-00915-UD-HNB Information 2550805 5.00 + 0.00 10065 20 17:04:22. +179-07:00 US 2017-04-28 E17-118-00031-P 2017-04-28 Accepted XXX + 2016-00894-UD-HNB Information 4716317 60.00 5.00 + 2.10 10065 20 17:1 +5:21.669-07:00 US 2017-04-28 P17-118-00019-P 2017-04-28 Accepted XXX + 2017-00917-UD-NJC Information 3539435 240.00 5.00 + 8.40 10127 20 17: +41:01.636-07:00 US 2017-04-28 E17-117-00041-P 2017-04-27 Accepted XXX + 2017-00915-UD-HNB Information 2550583 20.00 5.00 + 0.70 10127 20 17:5 +0:03.112-07:00 US 2017-04-28 E17-117-00003-P 2017-04-27 Accepted XXX + 99999999 Information 4715325 5.00 0.00 +10546 20 17:50:08.769-07:00 US 2017-04-28 E17-118-00020-P 2017-04-28 Accepted XXX + 2017-00916-UD-HNB Information 2550754 5.00 + 0.00 10127 20 18:01:28. +520-07:00 US 2017-04-28 P17-118-00018-P 2017-04-28 Accepted XXX + 2017-00917-UD-NJC Information 2550743 240.00 5.00 + 8.40 10249 20 18: +08:01.940-07:00 US 2017-04-28 E17-118-00024-P 2017-04-28 Accepted XXX + 2017-00913-UD-HNB Information 2550774 5.00 + 0.00 10249 20 18:27:45. +995-07:00 US 2017-04-28 E17-117-00020-P 2017-04-27 Accepted XXX + 2017-00913-UD-NJC Information 4715506 25.00 9.00 + 0.88 10137 20 18:3 +1:43.425-07:00 99 2017-04-28 E17-118-00009-P 2017-04-28 Accepted XXX + 99999999 Information 4716110 9.00 0.00 +10137 20 19:05:29.957-07:00 __END__

When I run this script it produces an output file twice the size of the expected result.

To summarize what's happening:

  • Read file and build a hash from the data.
  • Print incoming data and processed data to files. ( 'log1' and 'log2' ) Both are correct!
  • Convert the hash back to a file. ( 'log3' ) Incorrect!

    Problem is the 'log3' file has 2 keys for each input record. Can someone tell me how I should be building this hash?

    Thank you

    Regards...Ed

    "Well done is better than well said." - Benjamin Franklin

  • Replies are listed 'Best First'.
    Re: Building a hash from file and getting wrong result.
    by choroba (Cardinal) on May 15, 2017 at 20:16 UTC
      I'd guess keys is missing here:
      foreach my $recid ( reverse sort keys %SeqOrders ) # ~~~~

      So, you're mixing keys and values together and sorting them.

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

        Dear choroba,

        Thank you! I knew is was too basic to be a real Perl problem.

        Best Regards...Ed

        "Well done is better than well said." - Benjamin Franklin

    Re: Building a hash from file and getting wrong result.
    by kcott (Archbishop) on May 15, 2017 at 20:41 UTC

      G'day Ed,

      I didn't spend a huge amount of time going through your code; however, this part stood out as a potential problem:

      foreach my $recid ( reverse sort %SeqOrders ) ...

      That will expand all keys and values in the hash to form a list; that list will then be sorted and then reversed. Consider this minimal example of what's happening:

      $ perl -MData::Dump -e '%x = qw{a 1 b 2 c 3}; dd \%x; dd { reverse sor +t %x }' { a => 1, b => 2, c => 3 } { 2 => 1, a => 3, c => "b" }

      The foreach loop will set all keys and values to $recid; that will be twice the number of the keys and hence "an output file twice the size of the expected result".

      You probably want something closer to:

      my %rev_seq = reverse %SeqOrders; for my $recid (sort keys %rev_seq) { ... }

      — Ken

    Log In?
    Username:
    Password:

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

    How do I use this?Last hourOther CB clients
    Other Users?
    Others meditating upon the Monastery: (5)
    As of 2024-03-19 08:18 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found