Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: newbie need help with a simple code

by kielstirling (Scribe)
on Mar 05, 2013 at 03:55 UTC ( #1021740=note: print w/ replies, xml ) Need Help??


in reply to newbie need help with a simple code

I would use split.

#!/usr/bin/perl use Modern::Perl; use Data::Dumper; my @lines = ( "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", ); my @wants; for my $line (@lines) { push @wants, join ' | ', (split " ", $line)[3,6,7,10,11]; } print Dumper(\@wants);


Comment on Re: newbie need help with a simple code
Download Code
Re^2: newbie need help with a simple code
by perlmonk007 (Novice) on Mar 05, 2013 at 04:33 UTC
    I tried this, I did not understand what the pipeline does though. also it is not giving the desired result, will try modifying it a little
      It is a simple example of how you could use split to manage a line of text like you supplied. It will not work out of the box. You will in fact have to learn what the code does and customize it to your needs ... or even refactor it in a way that suits you better
        yes i am trying to play with it now. thanks for the help. will get back to you if i have any questions.
      ... I did not understand what the pipeline does ...

      The  | (pipe) character merely serves as a visual demarcation in the code example to allow the result of the operations to be better seen. Same thing as
          $selected = $1 . " | " . $2 . " | " . $3 . " | " . $4. " | " . $5;
      here.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1021740]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2014-09-15 03:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (145 votes), past polls