in reply to Re^2: Match Line And Combine Into One Line
in thread Match Line And Combine Into One Line

What makes you think that you are missing something?

  • Comment on Re^3: Match Line And Combine Into One Line

Replies are listed 'Best First'.
Re^4: Match Line And Combine Into One Line
by jlope043 (Acolyte) on Jul 21, 2016 at 19:00 UTC

    Hi Corion, well first I found a few mistakes I made, but my lines are wrapping and not breaking into new lines for each account. Corrected code below but not working as expected.

    use strict; use warnings; my %reformat; my $re = qr{^(H\d+,\d+,)(.*)$}; open (NEW, ">", "Notes_Test_OUTPUT.txt" ) or die "could not open:$ +!"; open (FILE, "<", "Notes_Test.txt") or die "could not open:$!"; while (<FILE>) { chomp; /$re/; push @{ $reformat{$1} }, $2; print NEW $_, join ' ', @{ $reformat{$_} } for keys %reformat; } close (FILE); close (NEW);

      In what way is it not working as expected?

      Maybe you can show some relevant input and relevant output and explain how the output differs from what you expect?

      Also, I notice that your indentation is very inconsistent. Consider applying a consistent way of indenting. For example, indent the complete loop body by four spaces below the while but don't indent anything else, as the while(...) { ... } statement is the only block within your program.

      While indenting, you might find that some things are within the block of your loop which you did not want there.