in reply to Re: parse array to replace specific spaces with pipes
in thread parse array to replace specific spaces with pipes

Ah, yes...that can be bad. I was able to structure the query to ignore middle initials, but a few slipped in.

__DATA__ 0211121253|Mike|Dell|ID06533 0211121253|A|Chris|Jones|ID02014 # this is not good 0211121253|Pa|Kettle|ID65255 0111119112|Mitch|Poo|ID05983

However, this leads me to the question: How do I remove the initial and/or period, leaving the data structure the same?

pseudo code: if row contains an element with one letter then remove letter continue pipe delimiting...

Thanks, vince

Replies are listed 'Best First'.
Re^3: parse array to replace specific spaces with pipes
by roboticus (Chancellor) on Jul 10, 2009 at 22:44 UTC
    neurotoxx:

    That would depend on your data source:

    • If it's a database, you could add some delimiters during the query
    • If it's a fixed-format flat file, you could take field lengths into account (substr, unpack)
    • If there are a fixed number of fields in the row, you could put all the "extras" in the name field
    • Perhaps you could take advantage of the fact that one of the fields matches /ID\d+/

    That's generally the problem with "squishy" data. Sometimes you have to look it over and get clever....

    ...roboticus
Re^3: parse array to replace specific spaces with pipes
by mzedeler (Pilgrim) on Jul 12, 2009 at 22:42 UTC

    You can use next to skip the rest of an iteration in a loop:

    while( ... ) { ... next if <something>; ... }

    The <something> is treated as an expression. Expressions can be $variable =~ /<regex>/ or just a single variable, which evaluates to false if undef, 0 or ''.