On , [EMAIL PROTECTED] said: >I used the regex in the end, the list will only ever be a few elements >long (and the script doesn't need to be efficient). Can't say I >understand it completely though (I was with you up until the first >comma) :)
Ok, here's an explanation: >> s/,(?=[^,]*$)/, or/; The (?=...) means "look ahead for...", so after the regex has matched a comment, it checks to see if the comma is followed by zero or more NON-commas and the end of the string. Because that part is in (?=...), the regex will make sure that sub-pattern matches WITHOUT ADVANCING IN THE STRING. Compare: ($x = "a, b, c, d") =~ s/,(?=[^,]*$)/, or/; print $x; # a, b, c, or d ($x = "a, b, c, d") =~ s/,[^,]*$/, or/; print $x; # a, b, c, or If you don't want the look-ahead, you could do ($x = "a, b, c, d") =~ s/,([^,]*$)/, or$1/; print $x; # a, b, c, or d but the point of the look-ahead is to avoid having to do that. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]