rmck wrote:
Hello,

This code below works. But I am wondering if it can be made more efficient:

while (<FHOREAD>) {

my $sport = (split(/\s/,$_))[8];
my $sdport = (split(/\s/,$_))[10];
next if $sport =~ /\D/;
next if $dport =~ /\D/;
   if ($sport =~ /^(20|21|22|25|53|80|109|110|123|137|161|443)$/ || $dport =~ 
/^(20|21|22|25|53|80|109|110|123|137|161|443)$/) { push @rest, $_ }
    else { print FHODATA}
  }
  print RFHODATA @rest;
}

8 and 10 are numbers 80,5000,53, etc..
will print if 8 0r 10 match my list to one file and it if dosen't match print to another file.




I looked at doing something like this but no good:

  while (<FHOREAD>) {
my $sdport = (split(/\s/,$_))[8],[10];

This I think is unclear, what were you trying to do with the above?


next if $sdport =~ /\D/;
    if ($sdport =~ /^(20|21|22|25|53|80|109|110|123|137|161|443)$/) { push @rest, $_ }
     else { print FHODATA}
  }
  print RFHODATA @rest;


As for making it more efficient, a hunch tells me it would be more efficient to use grep on your list rather than a regex with lots of alternation, however Perl/regex has some pretty cool optimizations so using Benchmark would be the best way to tell. I would think something along the lines of


my @ports = (20,21,22,25,53,80,109,110,123,137,161,443);
if ((grep $sport == $_, @ports) || (grep $dport == $_, @ports)) {
}

Or even so that we only need a single loop,

if (grep { $sport == $_ or $dport == $_ } @ports) {
}

HTH,

http://danconia.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to