On Thursday 08 November 2007 17:48, Paul Lalli wrote: > On Nov 8, 3:32 pm, [EMAIL PROTECTED] (Demian) wrote: > > > > I ran into a problematic file that combined two numeric columns > > into one: > > > > ATOM 325 CA GLU B 40 -30.254 72.432-297.620 1.00 > > 10.00 C > > ATOM 326 CA ASP B 41 -28.149 73.031-294.529 1.00 > > 10.00 C > > ATOM 327 CA GLU B 42 -27.716 76.690-295.429 1.00 > > 10.00 C > > ATOM 328 CA LEU B 43 -31.425 77.076-296.027 1.00 > > 10.00 C > > ATOM 329 CA VAL B 44 -32.237 75.542-292.673 1.00 > > 10.00 C > > ATOM 330 CA SER B 45 -29.850 77.900-290.914 1.00 > > 10.00 C > > ATOM 331 CA LEU B 46 -31.335 80.873-292.720 1.00 > > 10.00 C > > ATOM 332 CA GLN B 47 -34.837 79.809-291.801 1.00 > > 10.00 C > > > > I came up with a solution, but I'm sure there's an easier way. Is > > there a more elegant way of doing it? > > Split on either whitespace or on a minus sign that is both followed > by and preceded by a digit: > > my @fields = split /\s+|(?<=\d)-(?=\d)/, $line;
Close but that matches and removes the leading negative sign. my @fields = split /\s+|(?<=\d)(?=-\d)/, $line; Or you could do it like this: my @fields = map /-\d/ ? /-?\d+\.\d+/g : $_, split; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
