in reply to split function using multiple delimiters

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^2: split function using multiple delimiters
by JavaFan (Canon) on Dec 27, 2011 at 19:15 UTC
    How does a program that takes the OPs desired output, and turns in into the OPs input even remotely answer the question the OP is asking? Granted, it's not clear what part of the problem the OP is struggling with, but it is clear what the end result should be.

    And that end result is complete different from your solution.

      Hmm, don't know how I managed to mess that up. Oh well, here's the reverse:

      use strict; use warnings; my $raw = '<P_contrib-author>Allan Wigfield, Susan L. Klauda, and Jenn +a Cambria</P_contrib-author>'; $raw =~ s/<P_contrib-author>|<\/P_contrib-author>//g; print "<contrib-group>\n"; for (split /, (?:and )?/, $raw) { m/(.*) (.*)/; print "<name><surname>$2</surname><given-names>$1</given-names></n +ame>\n"; } print "</contrib-group>";
        Lots of good ideas, though split can be a dog with large volumes of data, like a book written at a frat party. I can't think of how to do it without using a match to follow, but a nice 2am ugly regex can do it all(tags have been pre-stripped):

        $_ = "Allan Wigfield, Susan L. Klauda, and Jenna Cambria";

           while( s/^(\w+(?:\s+\w\.)?)\s+(\w+)(?:,\s+(?:and\s+)?)// )
             { print "First Name: $1\nLast Name: $2\n";}

        It's ugly, but it works.