RE: Reading hash arrays in the order it was written
Fish, David wrote: Hello! The problem I am having is I am pulling data from a table in a certain order and loading it into the hash array but when I read the hash array it comes out in a different order than it is written. What I have done as a work around, is the read the data from a file that has it in the correct order. Is there away to build the hash so that it reads in the order it was created? Key creation and hash build: select statement ordering by certain columns .. $key = sprintf(%04d%07d%07d,$chk_num,$trans_seq,$dtl_seq); $midtlinfo{$key} = sprintf(%d|%d|%s|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%s|%s|%d|%d|%0.2f|%0. 2f|%0.2f, $se_chk_mi_seq, $obj_num, $business_date, $chk_num, $trans_seq, ); Reading of the hash: foreach $mk (keys %midtlinfo) @mrec = split(/\|/,$midtlinfo{$mk}); } 1. Push keys into an array as you add them to the hash and use that instead of 'keys %hash', ... or ... 2. Use the module designed for that purpose. See http://search.cpan.org/~gsar/Tie-IxHash-1.21/lib/Tie/IxHash.pm HTH -- Brian Raven --- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Reading hash arrays in the order it was written
Not inherent in the hash. You could store the ordinal value as one of the values in a hash of arrays, and then sort on that when you retrieve the values, but there is really no way to guarantee the order in which it will be retrieved from the hash is the same order in which it was inserted. To preserve your order, you need to use an array. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Fish, David Sent: Wednesday, November 19, 2008 7:58 AM To: [EMAIL PROTECTED]; perl-win32-users@listserv.ActiveState.com; [EMAIL PROTECTED] Subject: Reading hash arrays in the order it was written Hello! The problem I am having is I am pulling data from a table in a certain order and loading it into the hash array but when I read the hash array it comes out in a different order than it is written. What I have done as a work around, is the read the data from a file that has it in the correct order. Is there away to build the hash so that it reads in the order it was created? Key creation and hash build: select statement ordering by certain columns .. $key = sprintf(%04d%07d%07d,$chk_num,$trans_seq,$dtl_seq); $midtlinfo{$key} = sprintf(%d|%d|%s|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%s|%s|%d|%d|%0.2f|%0. 2f|%0.2f, $se_chk_mi_seq, $obj_num, $business_date, $chk_num, $trans_seq, ); Reading of the hash: foreach $mk (keys %midtlinfo) @mrec = split(/\|/,$midtlinfo{$mk}); } David Fish Senior Systems Analyst Property Systems Services Work (301) 380-3331 Fax (301) 644-7521 BlackBerry (301) 646-8985 [EMAIL PROTECTED] ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Reading hash arrays in the order it was written
Hi, I think the key's of the midtlinfo hash are not seen/get in the order you have populated it before, if iam not wrong. If so then a customized compare func could applied (on same terms when ordering by certain columns from tbl was done) while reading from the hash. Cheers/ --- On Wed, 11/19/08, Fish, David [EMAIL PROTECTED] wrote: From: Fish, David [EMAIL PROTECTED] Subject: Reading hash arrays in the order it was written To: [EMAIL PROTECTED], perl-win32-users@listserv.ActiveState.com, [EMAIL PROTECTED] Date: Wednesday, November 19, 2008, 9:27 PM Hello! The problem I am having is I am pulling data from a table in a certain order and loading it into the hash array but when I read the hash array it comes out in a different order than it is written. What I have done as a work around, is the read the data from a file that has it in the correct order. Is there away to build the hash so that it reads in the order it was created? Key creation and hash build: select statement ordering by certain columns .. $key = sprintf(%04d%07d%07d,$chk_num,$trans_seq,$dtl_seq); $midtlinfo{$key} = sprintf(%d|%d|%s|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%s|%s|%d|%d|%0.2f|%0. 2f|%0.2f, $se_chk_mi_seq, $obj_num, $business_date, $chk_num, $trans_seq, ); Reading of the hash: foreach $mk (keys %midtlinfo) @mrec = split(/\|/,$midtlinfo{$mk}); } David Fish Senior Systems Analyst Property Systems Services Work (301) 380-3331 Fax (301) 644-7521 BlackBerry (301) 646-8985 [EMAIL PROTECTED] ___ ActivePerl mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Reading hash arrays in the order it was written
Fish, David wrote: Hello! The problem I am having is I am pulling data from a table in a certain order and loading it into the hash array but when I read the hash array it comes out in a different order than it is written. What I have done as a work around, is the read the data from a file that has it in the correct order. Is there away to build the hash so that it reads in the order it was created? Wouldn't a stack (essentially just an array) be better than a hash? ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs