in reply to Re: data management script
in thread data management script

Thanks for telling me. I'm using a perl editor, so the loops were obvious to me. I've made it a bit eye friendlier.

The blasphemy I was referring to was my excessive use of loops, lack of subs, etc.

Commenting is helping me. There are still a couple of problems.

#!usr/bin/perl open LINKFILE, "linksource.dat" || die "no such file here"; while (<LINKFILE>) { #memorize title, then url; my ($title) = /title=(".*?")/; ($title) =~ s/"/'/g; ($title) =~ s/^\s+//g; ($title) =~ s/\s+$//g; my ($url) = /(component.*")/; ($url) = '"/' . $url; ($url) =~ s/"/'/; my $match = 0; open SQL, "mark.sql"; while (<SQL>) { @fields = split /,/ , $_ ; foreach $i(0 .. $#fields) { s/^\s+//, s/\s+$// for $fields[$i]; } print "\$fields[2]:|$fields[2]| \$title:|$title| \n" if ($t +itle eq "'Alternative Reds'");# monitor - stops after first A R hit?? next unless ($fields[2] eq $title); #skip it if it doesnt mat +ch next if ($fields[4] eq "'separator'"); #skip it if its not an +URL push @used, $fields[0]; ($fields[3] = $url) if ($fields[2] eq $title); my $sqlout = join "," , @fields; open NEWFILE , ">>newsql.sql"; print NEWFILE "$sqlout \n"; close NEWFILE; last; } # finished going through the SQL } #finished cycling through linkfile close SQL; close LINKFILE; #Now go through each record, check to see if the index field matches t +he used array, and if not, write the record open SQL, "mark.sql"; while (<SQL>){ @fields = split /,/ , $_ ; #compare first record element with the used array foreach (@used) { next if $fields[0] eq $_; # if the record has been used, dont use +it again print "\$used:|$_| \$fields[0]:|$fields[0]| \n"; #monitor my $sqlout = join "," , @fields; open NEWFILE , ">>newsql.sql"; print NEWFILE "$sqlout"; push @used, $fields[0]; close NEWFILE; last; } }

Replies are listed 'Best First'.
Re^3: data management script
by planetscape (Chancellor) on Jul 23, 2006 at 05:51 UTC