in reply to Re^2: split function using multiple delimiters
in thread split function using multiple delimiters

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>";

Replies are listed 'Best First'.
Re^4: split function using multiple delimiters
by angus_rg (Initiate) on Dec 28, 2011 at 23:03 UTC
    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.