in reply to hash help

Actually, if you run the code as posted with perl -d and the sample input you showed us, the problem would seem to be here:
if($acctn != $curr_acctn) { ...
Given the posted sample data, and the logic for assigning values to "$acctn" and "$curr_acctn", that "if" condition is only true for the first line of input (and on that iteration, the only thing you do inside the "if" block is $first_time = "no";

The debugger shows this if you set a break point at line #29, which is the first line inside the block of that is supposed to do all the real work:

foreach my $account (@account_list) { ...
The program runs to "completion" without ever reaching that line, because the $acctn is always equal to $curr_acctn (except on the first iteration, where line 29 doesn't come into play).

Since nothing inside that block is ever reached, nothing gets printed to the output file. If you're seeing some different problem, you must be using code and/or data that are different from what you've posted here.

It took me a while to figure out how your sample input relates to the desired output. Something like the following might suffice -- I'm not sure I really understand all the details of the intended application, but this creates the desired output for the given input:

#!/usr/bin/perl use strict; ( @ARGV == 2 and -f $ARGV[0] ) or die "Usage: $0 input.file output.file\n"; my $outname = pop @ARGV; open( OUT, ">", $outname ) or die "$outname; $!\n"; my $prev_rec; while (<>) { s/^42/CH /; s/\s+$/ LAB\n/; if ( ! $prev_rec ) { $prev_rec = $_; next; } if (( /4039140\s/ and $prev_rec =~ /4039139\s/ ) or ( /4039139\s/ and $prev_rec =~ /4039140\s/ )) { s/40391(?:39|40)(?=\s)/4039142/; print OUT; $prev_rec = ''; } else { print OUT $prev_rec; $prev_rec = $_; } } print OUT $prev_rec if ( $prev_rec );
That obviously pays no attention to lots of policy details implicit in the OP, but perhaps it provides a template that you can build on.

Replies are listed 'Best First'.
Re^2: hash help
by cesear (Novice) on May 04, 2011 at 12:34 UTC
    The code works for me. It may be I am running on windows and you on unix. Any ideas an how to modify the hash to get this to work?

    another sample input

    4201034500194 1212104039252 001 + 4201034300473 1212104034111 001 + 4201034300473 1212104033180 001 + 4201034300473 1212104039098 001 + 4201034300473 1212104039097 001 + 4201034300473 1212104039098 001 + 4201034300473 1212104039098 001 + 4201034600043 1212104034111 001 + 4201034600043 1212104033180 001 + 4201034600043 1212104039049 001 + 4201034600043 1212104039396 001 + 4201034600043 1212104039443 001 + 4201034600043 1212104039295 001 + 4201034600043 1212104039995 001 + 4201034500194 1212104033298 001 + 4201034500194 1212104039252 001 + 4201034500194 1212104039539 001 + 4601034500194 1211104039140 001 + 4201034100433 1212104367958 001 + 4201034300473 1212104039097 001

    output as my code is written now

    CH 01034500194 1212104033158 001 LAB CH 01034500194 1212104033240 001 LAB CH 01034500194 1212104039241 001 LAB CH 01034300473 1212104034111 001 LAB CH 01034300473 1212104033180 001 LAB CH 01034300473 1212104039098 001 LAB CH 01034300473 1212104039097 001 LAB CH 01034300473 1212104039098 001 LAB CH 01034300473 1212104039098 001 LAB CH 01034600043 1212104034111 001 LAB CH 01034600043 1212104033180 001 LAB CH 01034600043 1212104039049 001 LAB CH 01034600043 1212104039396 001 LAB CH 01034600043 1212104039443 001 LAB CH 01034600043 1212104039295 001 LAB CH 01034600043 1212104039995 001 LAB CH 01034500194 1212104033298 001 LAB CH 01034500194 1212104033158 001 LAB CH 01034500194 1212104033240 001 LAB CH 01034500194 1212104039241 001 LAB CH 01034500194 1212104039539 001 LAB CH 01034100433 1212104367958 001 LAB CH 01034100433 1212104367958 001 LAB CH 01034100433 1212104367959 001 LAB