in reply to Re: Problem Replacing Previously Found String
in thread Problem Replacing Previously Found String

Thanks for the reply. I need to avoid the "s///g" option because there may be multiple lines that I need to find and replace. Here is one of the input files:

/* ------------------------------------------------------------------- +------------------------------------------------ ** %%TableName%%.Fl ** ------------------------------------------------------------------- +------------------------------------------------ ** FastLoad Script for %%TableName%% ** ------------------------------------------------------------------- +------------------------------------------------ ** Generated by LoadGen ** ------------------------------------------------------------------- +------------------------------------------------ ** What | Who | When | Why ** ------------------------------------------------------------------- +------------------------------------------------ ** 1.00 | %%Author_Initials%% | %%Date%% | Original Version ** ------------------------------------------------------------------- +------------------------------------------------ ** | | | ** ------------------------------------------------------------------- +------------------------------------------------ ** | | | ** ------------------------------------------------------------------- +------------------------------------------------ */ .Show Versions; .Sessions %%Sessions%%; .LogOn %%TPID%%/%%User%%,%%Password%%; Database %%StagingDB%%; Drop Table ET_%%TableName%%; Drop Table UV_%%TableName%%; Drop Table %%TableName%%_Stage; Create Set Table %%TableName%%_Stage , No FallBack , No Before Journal , No After Journal , CheckSum = High ( %%Column_Name_Comma%% Varchar(%%Column_Size%%) ) Primary Index ( %%Primary_Index_Column_Comma%% ) ; .Set Record %%Record_Type%%; Begin Loading %%TableName%%_Stage Errorfiles ET_%%TableName%%, UV_%%TableName%%; Help Table %%TableName%%_Stage; Define File = %%Data_Dir%%%%Data_FileName%%; Show; ErrLimit %%ErrLimit%%; Insert Into %%TableName%%_Stage Values ( :%%Column_Name_Comma%% ); End Loading; .LogOff;


Doug

Replies are listed 'Best First'.
Re^3: Problem Replacing Previously Found String
by diotalevi (Canon) on Nov 16, 2004 at 23:52 UTC

    So what kinds of things go into $FindWhat and how is that different than @Column's hashes? Why don't you try out Text::Template? It already does this stuff and without having to invent your own parser.

    If all else fails, you could track what $-[0] and $+[0] are when you copy $1 and later use substr() to write back to $Template at those offsets with your replacement.

    I don't buy your argument about not using s/// on the grounds that it appears you're rejecting it on some faulty assumptions. Regardless, here's a s///ge alike without actually using s///.

    # Ala my $region_start = $-[0]; my $region_length = $+[0] - $-[0]; my $OriginalLine = $1; ... substr $Template, $region_start, $region_length, $ReplacementString;
      Thanks. I'll check out Text::Template, that's a new one for me. Nothing fancy goes into $FindWhat, just plain strings like COLUMN_NAME After my first post I discovered $-[0] and I have implemented a version using that. It's still buggy, but it's better. Doug