in reply to Re^2: Hash Help
in thread Hash Help

In that case you need to be smarter about recognizing records. There seems to be a line number associated with each line of a record so you can notice when the line number resets:

use warnings; use strict; use Data::Dump::Streamer; my %records; my @lines; while (! eof (DATA) or @lines) { my $line = <DATA>; $line ||= ''; # Avoid a bunch of defined tests chomp $line; next unless $line =~ /^([\s\d]\d)/ or @lines; if (! defined $1 or $1 <= @lines) { # Start of new record (or last record) - save previous my $id = substr $lines[0], 9, 5; $records{$id} = [@lines]; @lines = (); } push @lines, $line if length $line; } Dump (\%records); __DATA__ 10101ABC000019101L0001374686047S30339 GA &DOE C080229CR7 7 +00244 0000001 000000000 2 CR7 000 060714Q + Y 0000000000 000 3 00030339 3JO +HN DOE 36 423 MAIN STREET ATLANTA GA 30339 5 +000000000 +0080226I 052461 05241961 6Additional line 1 7and another additional line 10101ABC000029102 N D +3658 MAIN STREET 2 ATLANTA GA3033 +9 0001 3JOHN DOE 05241961INDV37468604 +7S 4 5

Perl reduces RSI - it saves typing

Replies are listed 'Best First'.
Re^4: Hash Help
by mmittiga17 (Scribe) on Nov 25, 2008 at 22:42 UTC
    with this new method how can I access each ID records lines 1 - X ? Before I could do it this way:
    #########REC01############## $line = $records{$id}[0]; $ACTNUM = substr $line, 2, 9 ; $TOT_AVBL_TO_PAY1 = substr $line, 32, 11; $TOT_AVBL_TO_PAY2 = substr $line, 43, 2; $TOT_AVBL_TO_PAY1 ="0" if (! $TOT_AVBL_TO_PAY1); $TOT_AVBL_TO_PAY2 ="0" if (! $TOT_AVBL_TO_PAY2); $TOT_AVBL_TO_PAY3 = join('.', $TOT_AVBL_TO_PAY1, $TOT_AVBL_TO_PAY2); $TOT_AVBL_TO_PAY = $TOT_AVBL_TO_PAY3; #########REC02############## $line = $records{$id}[1]; #########REC03############## $line = $records{$id}[2]; $MGN_FED_CALL_TOT1 = substr $line, 31, 11; $MGN_FED_CALL_TOT2 = substr $line, 42, 2; $MGN_FED_CALL_TOT1 ="0" if (! $MGN_FED_CALL_TOT1); $MGN_FED_CALL_TOT2 ="0" if (! $MGN_FED_CALL_TOT2); $MGN_FED_CALL_TOT3 = join('.', $MGN_FED_CALL_TOT1, $MGN_FED_CALL_TOT +2); $MGN_FEDSIG = substr $line, 30, 1; if ($MGN_FEDSIG eq "+") { $MGN_FED_CALL_TOT = "-" . $MGN_FED_CALL_TOT3 ; }else{ $MGN_FED_CALL_TOT = $MGN_FED_CALL_TOT3; }
    Thanks!!!!

      Look at the code. Think about the code. Think about the data structure. Examine the result from Dump. You have the answer already and it is time for you to do some thinking and just a little work. You can't expect to be spoon fed answers to every problem you have forever.

      perllol and perlref will help.


      Perl reduces RSI - it saves typing