Hi rjsaulakh,
A lot of suggestions for you:
- Use strict and warnings to make your life easier.
- Indent your code to better show the control flow
- Use the 3-argument form of open, and always check for success or failure.
- Always close files as soon as you're done reading from them.
- Use chomp (or chop) to remove the trailing newline, especially if the line represents a filename.
- Use foreach to easily iterate through lists
Putting them all together, you get the simplified:
#!/usr/bin/perl
# Always use these
use strict;
use warnings;
# Edit contains the complete path of the files to be edited
my $path = "/home/rjs/heena/edit" ;
# Getting a file handler (and test for success/failure!)
open(FL, "<", $path) or die "unable to open data file '$path' ($!)\n";
# Getting all the file names in the @array so that i can process the
# file one by one
chomp(my @array = <FL>);
# Close the data file
close(FL);
# Process each file
foreach my $file (@array) {
next if ($file =~ /^\s*$/); # Skip blank lines from datafile
open(FILE, "<", $file) or die "unable to open file '$file' ($!)\n"
+;
while(<FILE>) {
s/CONFIDENTIAL(.*?)own\s+risk/ /sm;
print;
}
close(FILE);
}
s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|