On 12-06-11 11:04 AM, lina wrote:
#!/usr/bin/env perl
use strict;
use warnings;
use autodie qw(open close);
use Carp qw(croak);
use 5.012;
my $tra=7;
my @files=("01".."40");
foreach(@files){
$tra=process_onefile("replica_index_$_.xvg");
}
sub process_onefile{
my $b;
# Don't use $b, choose a more meaningful name.
open my $fh, '<', @_;
# It's better to capture the parameters in an array
# with a meaningful name:
my @stream_params = @_;
# and later:
open my $stream_fh, '<', @stream_params;
while(<$fh>){
my @Tem_rep = split ' ', $_;
my $index = 1;
++$index until $Tem_rep[$index] == $tra;
# Use Perl's built-in function index for searching
# for one string inside another.
# See `perldoc -f index` for details.
say $index-1;
$b = $index-1;
# Set the variable first,
# and create a more meaningful diagnostic message.
}
return $b;
}
Thanks ahead for any improvement you may suggest
--
Just my 0.00000002 million dollars worth,
Shawn
Programming is as much about organization and communication
as it is about coding.
_Perl links_
official site : http://www.perl.org/
beginners' help : http://learn.perl.org/faq/beginners.html
advance help : http://perlmonks.org/
documentation : http://perldoc.perl.org/
news : http://perlsphere.net/
repository : http://www.cpan.org/
blog : http://blogs.perl.org/
regional groups : http://www.pm.org/
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/