sub loadtextconfig { # Read a text-based config file into a single-level hash, die on disk error # Usage: loadtextconfig(\%myhash, $myfilename); # Note: SJIS CAN BREAK/bakemoji e.g. a comma separated list of prefectures # Copyright 2001-2004 (c) Matt Rosin my ($href,$f) = @_; my ($i,$j) = (0,0); open(W,$f) || die "Content-type: text/html\n\n ERROR: Could not open $f $!"; while () { next if /^#/; # ignore commented lines $_ =~ s/\r|\n//g; # remove ending carriage return and/or ne wline s/^\s+//; # remove leading whitespace s/\s+$//g; # remove trailing whitespace next unless length; # skip blank lines ($i,$j) = split(/\t/,$_,2); # $j holds rest of line $j = "" unless (defined $j); $j =~ s/^\s+//; # remove leading whitespace $href->{$i} = $j; } close(W); # print "loadtextconfig $f:
\n" . Dumper($href) . "
\n"; }