The structure of the file is
Code: Select all
\nVAR-NAME: VAR-VALUE
\tVAR-VALUE
\tVAR-VALUECode: Select all
var1: tttttt rlkvf; ercm e,dro: lwmeurdiw
dkkdkdkdkdkadk;a
;lr er,fo4 o354,fp3,f5p4 of,more
var2: kdl;wskokfm3[p
var3: kf;l'dsv,eçrf
lse.cr dlrltkf;l
etc.I found a piece of PERL code that does precisely that.
Code: Select all
sub ParseData {
my $data = shift;
my %result;
while ($data =~ /(\S+?): (.*?)(?=\n[^ \t]|\Z)/sg) {
my ($key, $value) = ($1, $2);
$value =~ s/\n\t/\n/g;
$result{$key} = $value;
}
return %result;
}Code: Select all
function ParseData ($data) {
while ( preg_match( "/(\S+?): (.*?)(?=\n[^ \t]|\Z)/s", $data, $match ) ) {
$key = $match[1];
$value = $match[2];
$value = preg_replace( "/\n\t/", '\n', $value );
$result[$key] = $value;
}
return $result;
}For some reason, the function keeps on picking up the first var-name/var-value pair endlessly. If I use preg_match_all instead, $value and $key are arrays, and it still keeps on looping endlessly.