I am having a problem with a regex.
I am trying to parse a file (which has been previously marked with tags) and these tags replaced as variables.
Example input.txt
The quick brown fox jumps over the lazy dog
The stupid learner had trouble with regex
I manually edit input.txt with @tags@ to specify which words are to be variablized.
The quick @brown@ fox jumps over the lazy @dog@
The @stupid@ @learner@ had trouble with @regex@
The input.txt is passed to the script and I want it to be able top do something like this within the script..
Im trying to debug it like this...
while ( my $line = <FILE> ) {
chomp($line);
while ($line =~ s/@(\w*)@/\$i/g) {
print $line,"\n";
}
}
I want the lines resused within the script, but variablised.
Im not looking for solution, just tips on parsing the input lines and replace the matches as ouput to another file OR a variable $line1,$line2,$line3 etc, that can be reused, as shown the the example code.
Thanks in advance!!!
Evan
I am trying to parse a file (which has been previously marked with tags) and these tags replaced as variables.
Example input.txt
The quick brown fox jumps over the lazy dog
The stupid learner had trouble with regex
I manually edit input.txt with @tags@ to specify which words are to be variablized.
The quick @brown@ fox jumps over the lazy @dog@
The @stupid@ @learner@ had trouble with @regex@
The input.txt is passed to the script and I want it to be able top do something like this within the script..
Code:
$a = <STDIN>;
$b = <STDIN>;
$c = <STDIN>;
$d = <STDIN>;
.
.
for ($i=1; $i<=10; $i++) {
open(OUTPUTFILE,">$output");
print OUTPUTFILE "The quick $a fox jumps over the lazy $b\n";
print OUTPUTFILE "The $c $d had trouble with $e\n\n";
close(OUTPUTFILE);
}
Im trying to debug it like this...
while ( my $line = <FILE> ) {
chomp($line);
while ($line =~ s/@(\w*)@/\$i/g) {
print $line,"\n";
}
}
I want the lines resused within the script, but variablised.
Im not looking for solution, just tips on parsing the input lines and replace the matches as ouput to another file OR a variable $line1,$line2,$line3 etc, that can be reused, as shown the the example code.
Thanks in advance!!!
Evan