D
David G
I'm not any kind or perl expert, but have still managed to inherit a
number of perl scripts in a project. The original author is long
gone, and we don't have any perl expertise in house.
The problem is that one of the scripts reads in a text file, and
performs a translation operation on strings it finds enclosed in
double quotes. The perl in question is as follows:
{
open(INPUT, "$infile") or die "Can't open $infile: $!\n";
local $/ = undef;
$inputText = <INPUT>;
close(INPUT);
}
$inputText =~ s/"([^"]*)"/Translate(*TRANS, $1, "Generic String")/ieg;
OpenMakeDir(*OUTPUT, "$outfile") or die "Can't write $outfile \n";
print OUTPUT $inputText;
close(OUTPUT);
As far as I can tell, the entire operation is done in one go by the
line that starts "$input =~ ..."
The problem is that we need to have the operation not be performed if
the quoted string is itself enclosed in double angle brackets.
"This string is translated"
<<..."This string isn't"...>>
shows what is needed. If it makes any difference, angle bracket
enclosed sequences will never cross a line boundary.
For what it's worth I got the job because I'd mentioned that I do know
awk reasonably well. Ironically, this would be trivial for me to
craft in awk, but that doesn't help here.
So, is there any way to get the behavior we want? If it means
processing each line of the file in isolation, I'm 100% on board with
that, I just need to find a working solution.
TIA
David G.
number of perl scripts in a project. The original author is long
gone, and we don't have any perl expertise in house.
The problem is that one of the scripts reads in a text file, and
performs a translation operation on strings it finds enclosed in
double quotes. The perl in question is as follows:
{
open(INPUT, "$infile") or die "Can't open $infile: $!\n";
local $/ = undef;
$inputText = <INPUT>;
close(INPUT);
}
$inputText =~ s/"([^"]*)"/Translate(*TRANS, $1, "Generic String")/ieg;
OpenMakeDir(*OUTPUT, "$outfile") or die "Can't write $outfile \n";
print OUTPUT $inputText;
close(OUTPUT);
As far as I can tell, the entire operation is done in one go by the
line that starts "$input =~ ..."
The problem is that we need to have the operation not be performed if
the quoted string is itself enclosed in double angle brackets.
"This string is translated"
<<..."This string isn't"...>>
shows what is needed. If it makes any difference, angle bracket
enclosed sequences will never cross a line boundary.
For what it's worth I got the job because I'd mentioned that I do know
awk reasonably well. Ironically, this would be trivial for me to
craft in awk, but that doesn't help here.
So, is there any way to get the behavior we want? If it means
processing each line of the file in isolation, I'm 100% on board with
that, I just need to find a working solution.
TIA
David G.