in reply to Problem with program structure
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |