[boulder.pm] line/loop optimization?

Jeff Walker jwalker at matchlogic.com
Tue May 8 11:47:42 CDT 2001


I guess you could do something like this:

while( defined( $Line = <TemplateIn> ) ) {
  $Line = chomp( $Line );
  if ( $Line =~ /(OPTION.)/ ) {
      $Line = $` . $ConfigOptions{"$1"} . $';
  }
}

I didn't try this, but if I understand the question, I think that will work.
There is probably another way to do it with "s/OPTION./..../", but I can't
think of how to expand "$ConfigOptions{"$1"}" inside a s///, or even if that
will really work.

There might be a problem with the above, however.  I think it will only
operate on the first OPTIONX on the line.  This may not be a problem, but
who knows.  I think maybe if you replace "if" with "while" that may work,
but I haven't ever tried anything like that, so you should test it before
using it. (as always, I suppose)

HTH

-- 
Jeff Walker                   MatchLogic, Inc.
jwalker at matchlogic.com        7233 Church Ranch Blvd.
Voice 1 (303) 222-2105        Westminster, CO  80021
Fax   1 (303) 222-2001        www.matchlogic.com


-----Original Message-----
From: Robert L. Harris [mailto:Robert.L.Harris at rdlg.net]
Sent: Tuesday, May 08, 2001 10:28 AM
To: Boulder Perl Mongers
Subject: [boulder.pm] line/loop optimization?




Ok,  I'm currently reading in a "config file" that says something like,

OPTION1=value1
OPTION2=value2
OPTION3=value3
OPTION4=value4
OPTION5=value5


and then reading in a template file that will have OPTIONX embeded.  The 
values will likely change per run so they can't be hard coded.  I'm 
currently doing something like this:

@Keys=keys(%ConfigOptions);
while(<TemplateIn>) {
  chomp;
  $Line=$_;
  foreach $i (@Keys) {
    $Line =~ s/$i/$ConfigOptions{$i}/;
  }
}


Is there a better way to do a line by line substitution instead of looping
through @Keys each line?

Robert


:wq!
---------------------------------------------------------------------------
Robert L. Harris                |  Micros~1 :  
Senior System Engineer          |    For when quality, reliability 
  at RnD Consulting             |      and security just aren't
                                \_       that important!
DISCLAIMER:
      These are MY OPINIONS ALONE.  I speak for no-one else.
FYI:
 perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'



More information about the Boulder-pm mailing list