G
George Mpouras
I must discover all possible field names of a key/value file.
The properties of the file are unknown so I must be a little creative.
The values optional can have whitespaces inside "..."
its key/value separated with a space from the next pair.
Do you thing the following is ok ?
#!/usr/bin/perl
use strict;
use warnings;
while(<DATA>) { chomp;
while ( /([^=]+)=("[^"]+"|\S+)/g ) {
my ($key, $val) = ($1, $2);
$val =~s/^["\s]*(.*?)["\s]*$/$1/;
print "*$key* *$val*\n"
}
print "--------\n"
}
__DATA__
f1=hello f2= f3="foo" f4="hello world"
f6="day" f7="day & night" f8=100
The properties of the file are unknown so I must be a little creative.
The values optional can have whitespaces inside "..."
its key/value separated with a space from the next pair.
Do you thing the following is ok ?
#!/usr/bin/perl
use strict;
use warnings;
while(<DATA>) { chomp;
while ( /([^=]+)=("[^"]+"|\S+)/g ) {
my ($key, $val) = ($1, $2);
$val =~s/^["\s]*(.*?)["\s]*$/$1/;
print "*$key* *$val*\n"
}
print "--------\n"
}
__DATA__
f1=hello f2= f3="foo" f4="hello world"
f6="day" f7="day & night" f8=100