SPUG: ifs and whiles and hashes...

charles.e.derykus at boeing.com charles.e.derykus at boeing.com
Wed Aug 18 20:44:04 CDT 1999



>        if ($dbaseLine =~ m/^\"(?:.*)\",\"(.*)\",\"(.*)\"/)  {
>
>                $hash{'key1'} = $1;
>                $hash{'key2'} = $2;
>                #etc...
>  ..

> however, my program has 26 of these '\"(.*)\",' in the 'if

As Doug noted, this regex'll backtrack quite a bit. Another 
possibility for speedup would be to break up the regex
and use the '\G' operator and the 'g' modifier for the
repetitive portion:

my $count = 26;        
my $pattern = '[^"]*';

if (  /^"(?:[^"]*",)/g        # note: need 'g' here 
              and                  
      ( @matches = /\G"($pattern)",?/g ) == $count 
   )  
 {       
      @hash{@key_names) = @matches;
 }


Regards,
--
Charles DeRykus
        

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list