Hello E. > Hello! > I want to read this file into an array. > How can i just get 4, 5, 6,7,8 into an array? > And later, how can i get the contents out of this array? > 1) 2) 3) 4) 5) 6) > 7) 8) 9) 10) 11) > ATOM 2909 CG1 VAL B 183 1.130 28.458 104.360 1.00 > 23.04 C > ATOM 2910 CG2 VAL B 183 0.996 29.769 102.236 1.00 > 24.61 C > ATOM 2911 N THR B 184 3.313 31.739 103.453 1.00 > 25.98 N > ATOM 2912 CA THR B 184 3.261 33.012 104.149 1.00 > 29.31 C > ATOM 2913 C THR B 184 1.911 33.642 103.859 1.00 > 29.26 C > ATOM 2914 O THR B 184 1.442 33.626 102.720 1.00 > 28.75 O > regards
Hmmm... your description is a bit "small", as Ramprasad A Padmanabhan already wrote. I reformatted your lines and guess that you have a fixed format file with every value in well defined columns, and every line with the same length. _IF_ this is the case, then you _could_ follow several strategies: a) split every line into chars and extract the appropriate b) use a regex extracting according to positions c) use a regex extracting patterns I think the best and simplest method would be strategy b): - independent from char/alpha/digit at the positions - goes also if no spaces between values Since your lines are line breaked, I use a simplified example. For reading in a file line by line into a variable, see Steven's code. I only demonstrate the extraction of one already read line; and I extract the 1st and the 3rd value (you can easily adapt it to your actual line layout, I suppose you will have some variable descriptions with start- and end-positions) # intro # use strict; use warnings; # a line example # my $line='ATOM 2909 CG1 VAL B'; # incomplete demo line! # direct extraction (result pieces left aligned). # Note the o modifier and the () around the 1st and 3rd piece # my @parts= $line=~/^(.{7}).{6}(.{6}).{5}/o; # trim right space away. I'm shure there is a shorter # and more elegant solution # @parts= map { do {$_=~s/\s*$//; $_ } } @parts; # print # print join ", ", @parts; print "\n"; # This prints: ATOM, CG1 If you need more detailed explanation of the code, just ask - and also consult the documentation: perldoc perlre perldoc perldata (at least) greetings joe -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>