Please could people advise me on whether I need to start the program again.

Ditto as above wrt what all the others wrote. Your program makes my eyes bleed, period. Thus if you ask me, then yes: your should rewrite it from scratch. Of course you should first learn how to do so rather than posting either the same very snippets over and over again or whole programs with vague rfcs attached to them. Consider:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper 'Dumper'; my $dir = "csv/"; my @filenames = grep /csv/ && -f "$dir/$_" => do { opendir my $dh, $dir or die "Can't opendir `$dir': $!\n"; readdir $dh; }; my @place; open my $prep, "$dir/$filenames[0]" or die "Can't open file `$filenames[0]': $!\n"; while (<$prep>) { next unless /^([^,]+),([^,]+),(?:\d+,){4},(?:\d+,){4},(?:\d+,){3}/ +; my $place = "$1_$2"; my $reglookup = "$1,$2"; print "\n", '>' x 21, "\n", $reglookup, "\n", '>' x 21, "\n"; y/ /_/ => y/\"//d for $place_tag_string; s/ /\\s/g => s/([,\"()&])/\\$1/ge for $reglookup_tag_string; push @place, { type => $1, name => $2, tag => $place, reg => $reglookup }; } close $prep; my $filenumber; for (@place) { print "\n@@@@@@@@@@\n\n" $_->{reg}, "\n\n"; for my $file (@file_names) { my ($rl, $pt) = @{ $_ }{qw/reg tag/}; $filenumber++; print "\n\n\n\n$rl, $dir, $file, $filenumber, $pt\n\n\n\n"; print_out_files($rl, $dir, $filename, $filenumber, $pt); } } sub print_out_files { my %files; my ($rl, $dir, $file, $filenumber, $pt) = @_; my $Is_it_printed = 0; $files{Outfile} = "Result/Result_$pt.txt"; $files{Outfile_B} = "Result/Result_B_$pt.txt"; open my $ofh, '+>', $files{Outfile} or die "Can't create output file `$files{Outfile}': $!\n"; open my $ofh, '+>', $files{Outfile_B} or die "Can't create output file `$files{Outfile_B}': $!\n";

Which I got out GrandFather's improved version of your program by further:

This is not a complete rewrite because arrived at the point at which I stopped I had grown completely tired, the rest of your code scared me and hey, nobody is paying me for this... I hope you get the picture and can go on yourself.

Consider that where I stopped I got 53 lines of reasonably terse code out of your original 99 ones. And I didn't want to change the logic too much, too.


In reply to Re: Problem with program structure by blazar
in thread Problem with program structure by Win

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.