Can names have embedded spaces? Can the "haven't got a clue" part have embedded spaces?
Without knowing this, we can't know whether to break
MOTEL GOLDEN LEEUW <A225>
into
(MOTEL)()(GOLDEN LEEUW <A225>)
or
(MOTEL GOLDEN LEEUW)()(<A225>)
Assuming for a moment that the latter is the correct way to divide the field, you could do something like
while ( <DATA> ) {
if ( /^(.*)\s*($Pred_re)\s*(.*)$/ ) {
($name,$pred,$unknown) = ($1, $2, $3);
} else {
($name,$unknown,$pred) = /^(.*)\s*(\S*)$/;
}
}
Updated: to tweak the whitespace matching.
Update 2: Bah. Forget the feeble effort above.
my $Prep_Re=join '|',('VAN DER','VAN DE','DEN','DE','VAN');
while ( <DATA> ) {
chomp;
if ( /^(.*)\s+($Prep_Re)\b\s*(.*)$/ ) {
($name, $prep, $other) = ($1, $2, $3);
}
elsif ( /^(.*)\s+($Prep_Re)\s*$/ ) {
($name, $prep, $other) = ($1, $2, "");
}
elsif ( /^(.*)\b\s+(\S+)$/ ) {
($name, $prep, $other) = ($1, "", $2);
}
else {
($name, $prep, $other) = ($_, "", "");
}
print "$name|$prep|$other\n";
}
__DATA__
WINTER DE <A240>
ZANDEN VAN DER ŤAť
JENSEN 230
WOODHEAD <D>
BRINK 130,-
HEYDIER DEN <240>
SMITSER (4X115PJ)
LINDEN VAN DER
MOTEL GOLDEN LEEUW <A225>
__END__
WINTER|DE|<A240>
ZANDEN|VAN DER|ŤAť
JENSEN||230
WOODHEAD||<D>
BRINK||130,-
HEYDIER|DEN|<240>
SMITSER||(4X115PJ)
LINDEN|VAN DER|
MOTEL GOLDEN LEEUW||<A225>
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.