in reply to Clean Code - What a mess...
my @ins_fields= ("log"); my @ins_values= ("''"); for (1..25) { $writer[$_ -1] = "value of writer". ($_-1) ; push @ins_fields, "log$_"; push @ins_values, $writer[$_ -1]; } my $ins_fields = join ",", @ins_fields; my $ins_values = join ",", @ins_values; print "INSERT INTO $log ($ins_fields)\nVALUES ($ins_values)";
some of these can be 'optimized' by using tr///; always consider this when you have a direct 1-to-1 relationship between characters in and characters out, or when deleting chars. Your final 2 can be reduced to one regex, whose form depends on the answer to "are series of 4 or more underscores possible? would they be relevant in ways that 2 and 3 aren't?" Take a look at this snippet :$findings=~s/,//g; $findings=~s/ /_/g; $findings=~s/\///g; $log="$findings"; $log=~s/:/_/g; $log=~s/\./_/g; $log=~s/___/_/g; $log=~s/__/_/g;
The first one will take up any number of underscores and replace with a single underscore. The second will look for only two or three in a row, if there's 4 or more, it doesn't care. Whether this is relevant depends on your data.for (1..10) { my $foo = "_" x $_; $foo =~ s/_+/_/; print "method one : $foo\n"; my $foo = "__" x $_; $foo =~ s/___?/_/; print "method two : $foo\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: random DBI suggestion
by PyroX (Pilgrim) on Nov 29, 2001 at 04:26 UTC | |
|
Re: random DBI suggestion
by grinder (Bishop) on Nov 29, 2001 at 18:57 UTC |