I'm starting in perl and I made this script to read a file. But the file contains more than 10k lines, how to limit reading to 5 lines, or between line 5 and 10?
my $pdb = Structure->new(
-file => 'arq.txt',
-format => 'PB'
);
my $strutur = $pb->next_structure;
foreach my $chain ($strutur->get_chains) {
my $chain_id = $chain->id;
foreach my $residue ($strutur->get_residues($chain)) {
my $residue_id = $residue->id;
print "Chain: ".$chain_id."\tResidue: ".$residue_id."\n";
}
}
First i tried display five lines and break the loop.
use strict;
while(my $strutur = $pb->next_structure) {
print "Chain: ".$chain_id."\tResidue: ".$residue_id."\n";
last if $. == 5;
}
close $pb;
And get the output
Global symbol "$strutur" requires explicit package name (did you forget to declare "my $estrutura"?)
Then i tried
use strict;
while( my $residue_id = $residue->id) {
print "Chain: ".$chain_id."\tResidue: ".$residue_id."\n";
last if $. == 5;
}
close $residue;
That made an infinite loop with just the first line