Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
A collegue of mine is working on parsing a file, which
is part of a database... The person that wrote this
database has kinda screwed up, because he/she used 1 field
for 3 values, I`ll explain:

In The Netherlands, a surname CAN be prepended by (amongst
others) one of the following:
'VAN DER','VAN DE','DEN','DE','VAN' ...
I have no clue what this is called in English, but
I would like to call it a 'prependition' :)

Anyways... The fields in every line are:

NAME<Mandatory> PREPENDITION<maybe> HAVENT_GOT_A_CLUE<maybe>

I wanted to help, and I`ve tried different ways to parse
this, and I only have a little sample data, but I came up
with this:
#!/usr/bin/perl -w use strict; my $Prep_Re=join '|',('VAN DER','VAN DE','DEN','DE','VAN'); print "Name\t\tPrependition\t\tWhatever\n"; while (<DATA>) { chomp; s/\s{2,}/ /g; my ($Name,$Prep,$Unknown); ($Name,$Prep,$Unknown)=($`,$1,$') if (/ ($Prep_Re)/); ($Name,$Unknown)=($`,$1) if ((!$Name)&&(/ (\S*?$)/)); $Prep||=''; print "$Name\t\t$Prep\t\t$Unknown\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>

It works for my sample data, but I can already think of
cases where it won`t work... and... I have a gut-feeling
this can be done better (I`m not a regex-wiz) ...

Any pointers ?

GreetZ!,
    ChOas

print "profeth still\n" if /bird|devil/;

In reply to 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 chilling in the Monastery: (4)
As of 2024-04-25 21:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found