Permalink
Browse files

csv2html: minor adjustments

* assert that global variables are all caps, locals are lowercase
* maintain a separate global line count. only print to stdout after
parsing if this line count is greater than 0.
  • Loading branch information...
1 parent ead7f28 commit d512112837acf6150cbd31c8256099064539e23a @falconindy committed Aug 23, 2010
Showing with 6 additions and 6 deletions.
  1. +6 −6 csv2html
View
@@ -2,12 +2,13 @@
NUMFIELDS=0
OUT=()
+TLC=0
to_html() {
- local LC=0 # line counter in case of error
+ local lc=0 # line counter in case of error
while IFS=',' read -r -a items; do
- (( ++LC ))
+ (( ++lc ))
OUT+=("\t<tr>\n") # start row
# skip blank lines, but not lines with empty fields
@@ -27,6 +28,8 @@ to_html() {
OUT+=("\t</tr>\n") # end row
+ (( TLC += lc ))
+
# replace blank fields with a dummy value so read doesn't skip them
done < <(sed 's/^,/==NULL==,/;
s/,,/,==NULL==,/g;
@@ -47,8 +50,5 @@ else
done
fi
-OUT+=("</table>\n") # footer
-
-echo -e "${OUT[@]}"
-
+(( TLC > 0 )) && OUT+=("</table>\n") # footer

0 comments on commit d512112

Please sign in to comment.