Changeset 24586 for main/trunk/greenstone2/perllib/cfgread.pm
- Timestamp:
- 2011-09-13T20:54:35+12:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/cfgread.pm
r20390 r24586 137 137 } else { 138 138 print STDERR "cfgread::read_cfg_file couldn't read the cfg file $filename\n"; 139 } 140 141 return $data; 142 } 143 144 # If the cfg file contains unicode characters, use this method to read from it 145 # Used by HFileHierarchy classifier, since an HFile is read as a cfg file, but 146 # can contain unicode characters. 147 sub read_cfg_file_unicode { 148 my ($filename, $stringexp, $arrayexp, $hashexp, $arrayarrayexp, 149 $hashhashexp) = @_; 150 my ($line); 151 my $data = {}; 152 153 if (open (COLCFG, $filename)) { 154 binmode(COLCFG,":utf8"); 155 while (defined ($line = &read_cfg_line('COLCFG'))) { 156 if (scalar(@$line) >= 2) { 157 158 #map { decode("utf8",$_) } @$line; #use Encode; 159 160 my $key = shift (@$line); 161 if (defined $stringexp && $key =~ /$stringexp/) { 162 $data->{$key} = shift (@$line); 163 164 } elsif (defined $arrayexp && $key =~ /$arrayexp/) { 165 push (@{$data->{$key}}, @$line); 166 167 } elsif (defined $hashexp && $key =~ /$hashexp/) { 168 my $k = shift @$line; 169 my $v = shift @$line; 170 $data->{$key}->{$k} = $v; 171 } elsif (defined $arrayarrayexp && $key =~ /$arrayarrayexp/) { 172 if (!defined $data->{$key}) { 173 $data->{$key} = []; 174 } 175 push (@{$data->{$key}}, $line); 176 } 177 elsif (defined $hashhashexp && $key =~ /$hashhashexp/) { 178 my $k = shift @$line; 179 my $p = shift @$line; 180 my $v = shift @$line; 181 if (!defined $v) { 182 $v = $p; 183 $p = 'default'; 184 } 185 $data->{$key}->{$k}->{$p} = $v; 186 } 187 } 188 } 189 close (COLCFG); 190 191 } else { 192 print STDERR "cfgread::read_cfg_file_unicode couldn't read the cfg file $filename\n"; 139 193 } 140 194
Note:
See TracChangeset
for help on using the changeset viewer.