in reply to data management script

Apologies for not answering your question, but I was distracted by your "blasphemous coding technique" (as you put it) - or as I'd put it - bad indentation, style, etc. Please don't place 4 separate statements on the same line!

my ($title) = /title=(".*?")/; ($title) =~ s/"/'/g; ($title) =~ + s/^\s+//g;($title) =~ s/\s+$//g;

Please properly indent things like for loops and other blocks. This is just one example, but you really lose a lot of information/visual cues that can help make heads or tails out of your code.

foreach $i(0 .. $#fields) { s/^\s+//, s/\s+$// for $fields[$i]; #print "\$fields[$i]:$fields[$i] \n"; }

Honestly, it's not that difficult to clean things up manually - but if you just can't coerce yourself into some structure, at the very least, please run your code through perltidy. I (and perhaps many others) won't read your code, much less help you on it, otherwise.



--chargrill
$,=42;for(34,0,-3,9,-11,11,-17,7,-5){$*.=pack'c'=>$,+=$_}for(reverse s +plit//=>$* ){$%++?$ %%2?push@C,$_,$":push@c,$_,$":(push@C,$_,$")&&push@c,$"}$C[$# +C]=$/;($#C >$#c)?($ c=\@C)&&($ C=\@c):($ c=\@c)&&($C=\@C);$%=$|;for(@$c){print$_^ +$$C[$%++]}

Replies are listed 'Best First'.
Re^2: data management script
by mkahn (Beadle) on Jul 22, 2006 at 16:42 UTC
    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; } }