Hi, Perhaps you can use the /\G.../gc idiom and develop lex like engine. see: http://search.cpan.org/~nwclark/perl-5.8.8/pod/perlfaq6.pod#What_good_is_\G_in_a_regular_expression?_
and: http://search.cpan.org/~nwclark/perl-5.8.8/pod/perlop.pod#Regexp_Quote-Like_Operators >From my experience breaking complicated regular expression into some small >ones with the /\G.../gc idiom improve performance. Yaron Kahanovitch ----- Original Message ----- From: "JeeBee" <[EMAIL PROTECTED]> To: beginners@perl.org Sent: 11:49:24 (GMT+0200) Africa/Harare יום רביעי 18 יולי 2007 Subject: Re: Optimize my script Because I'm trying to match this regular expression a lot of times, that could very well be the point to improve. I can imagine this is the slowest part of the script: my $exp = "nan|-?inf|[0-9\.e\+\-]+"; my $stat_pat = "(?:\\s+($exp))(?:\\s+($exp))" . # $1 number of samples, $2 minimum "(?:\\s+($exp))(?:\\s+($exp))" . # $3 maximum, $4 sum "(?:\\s+($exp))(?:\\s+($exp))" . # $5 average, $6 variance "(?:\\s+($exp))(?:\\s+($exp))"; # $7 skewness, $8 kurtosis Which I'm using like this many times: foreach my $stat_key (@stat_var_keys) { if($line =~ m/^\s*$stat_key$stat_pat/) { # $6 == "variance" $map{"var_$stat_key"} = $6; } } Can this regular expression be changed to do the same a be a lot faster? Thanks in advance, JeeBee. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/