Hello,

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?

Thank you.

_____________________________________________________

#!/usr/bin/perl
#
use strict;
use warnings;

my $numstring= "-100.00-400.34";

my @pieces= split /([-])/, $numstring;

my @nums;

for (my $k=0; $k<=$#pieces; $k++){
  if ($pieces[$k] eq "-") {
    push @nums, "$pieces[$k]$pieces[$k+1]";
    $k++;
    next;
  }
  elsif($pieces[$k]=~ /\d+/) {
    push @nums, $pieces[$k];
  }
}

map {print $_ . "\n"} @nums;

______________________________________________


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to