Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-19 05:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found