
Chris Charley
User
Oct 7, 2011, 6:03 PM
Post #7 of 7
(3062 views)
|
This may be a solution. #!/usr/bin/perl use strict; use warnings; my $code = <<EOF; data output; set input; if varname=1 then var_flag=1; else var_flag=0; run; EOF my $keywords = <<EOF; data set if then else run EOF my $keyword; { local $/; # slurp the keyword file (in this limited scope) open my $kw, "<", \$keywords; $keyword = join "|", split ' ', <$kw>; close $kw; } open my $c, "<", \$code; while (<$c>) { s/($keyword)/uc $1/eg; print; } close $c; __END__ { local $^I = '.bak'; local @ARGV = ("code.txt", ..., ... ); while (<>) { s/($keyword)/uc $1/eg; print; } } The code beyond the __END__ would do inplace editing if this bit of code replaced the code above for the while loop. It is also contained in a scope, (between the opening brace { and the closing brace }.
(This post was edited by Chris Charley on Oct 9, 2011, 6:03 PM)
|