To add to what the other monks have said ...
There's an error and at least one weirdness in your code:
- the next line works by accident. It's checking if $filename in the current directory is a directory or not. If there happens to be a directory in the current directory that has the same name as a file in your summary spr directory, it will be skipped.
- your map-in-void-context looks like it might just be
trying to act as chomp. If so, it's just
chomp(@{$sspr_hash{$file_name}} = <FH>); with no map afterwards.
- grep works on lists but you're only using it on
a single item. Valid but strange. Typically people
would just do $line =~ /$old_schema/i
Also, I'm not sure why you've divided your task into two
parts like this. Is there a reason you're reading the contents of the files before you do any processing? If not,
I'd just do it all in one go like this:
#!/usr/bin/perl
use warnings; use strict;
my $ssprdir = "/apps/inst1/metrica/TechnologyPacks/ON-SITE/summaryspr/
+";
opendir(my $sspr, $ssprdir) or die "Can't read $ssprdir - $!\n";
my @files = grep { ! -d $_ } map { "$ssprdir/$_" } readdir $sspr;
closedir $sspr;
for my $file (@files) {
unless (open(my $fh, "<", $file)) {
warn "Unable to open $file - $!\n";
next;
}
# ...
while (<$fh>) {
next unless /$old_schema/i;
# ...
print "$old_schema|$new_schema_str|$found_status|$migratestr|$
+rename_str|$file\n";
}
close $fh;
}
__END__
Also, if $old_schema is really supposed to be a string and not a regular expression, you might consider using index instead of engaging the RE engine.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.