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>

In reply to Re: Can this be parsed ? by dws
in thread Can this be parsed ? by ChOas

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.