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.

In reply to Re: hash help by graff
in thread hash help by cesear

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.