CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced: Re: [manojrayan] Urgent Help: Edit Log



Chris Charley
User

Oct 7, 2011, 6:03 PM


Views: 3621
Re: [manojrayan] Urgent Help

This may be a solution.

Code
 #!/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)


Edit Log:
Post edited by Chris Charley (User) on Oct 7, 2011, 6:05 PM
Post edited by Chris Charley (User) on Oct 8, 2011, 6:21 PM
Post edited by Chris Charley (User) on Oct 9, 2011, 6:03 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives