I have a subroutine outputs an array like this

ATOM 1276 CB ASP B 63 52.957 58.788 67.683 1.00 44.59 C

ATOM 1280 N GLY B 64 52.075 55.496 66.522 1.00 35.29 N

ATOM 1281 CA GLY B 64 51.005 54.534 66.322 1.00 32.64 C

ATOM 1282 C GLY B 64 49.693 55.103 65.854 1.00 30.87 C

ATOM 1283 O GLY B 64 48.630 54.545 66.092 1.00 27.93 O

ATOM 1284 N LYS B 65 49.739 56.255 65.189 1.00 31.10 N

ATOM 1285 CA LYS B 65 48.527 56.912 64.720 1.00 33.91 C

ATOM 1286 C LYS B 65 48.629 57.147 63.216 1.00 32.04 C

ATOM 1287 O LYS B 65 49.675 57.571 62.721 1.00 31.87 O

here each line is an element of an array, but i need only certain columns of this output. for example the first row is all ATOM, but i do not need any of that, could anyone please tell me, how to extract the required rows, a simple psuedocode would help me a lot.

UPDATE #1

ok i used the regular expressions code that was suggested and I am facing a problem with the output, the array in the output is empty, could some one tell me where I am going wrong

the code is after i get the array from the subroutine, the array consists of the output as the format above and every line of the output is a single element of the array. If i type $line1 i get the first line.

my @opin = &attributes(); my @lines = @opin; my ($selected, @selections); for my $lines(@lines) { if ( $lines =~ /ATOM\s+ \d+\s+ ([A-Z]{1,2})\s+ ([A-Z]{3})\s+ [AB]\s+ \d+\s+ \d+\.\d+\s+ \d+\.\d+\s+ \d+\.\d+\s+ \d+\.\d+\s+ \d+\.\d+\s+ [CNO]$/x ) { $selected = $1 . " | " . $2 ; push @selections, $selected; } } print O "@selections"; close (O); close (I);

any help would be appreciated.


In reply to newbie need help with a simple code by perlmonk007

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.