in reply to parse array to replace specific spaces with pipes

neurotic:

While the other monks have provided the answer to your question, I'm going to provide you with a cautionary example:

0213312247 Richard O. Boticus ID19897

...roboticus

Replies are listed 'Best First'.
Re^2: parse array to replace specific spaces with pipes
by neurotoxx (Novice) on Jul 10, 2009 at 16:56 UTC

    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

      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

      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 ''.