Thanks all who assisted, especially Bill for the rewriting part and others for
the regex syntax.
The script rewrites the files but nothing is replaced. When I escape the space
as \s+ or \s it signals an error of unrecognized escape \s.
Could it be the regex are written or is it impossible to do the required
substitution?
Help appreciated.
Zilore
use strict;
use warnings;
use POSIX;
use File::Path;
use File::Copy;
my $debug=1;
my $Grib_dir = 'grib_files';
opendir DIR, $Grib_dir or die "opendir failed on $Grib_dir: $! ($^E)";
while (my $file = readdir DIR) {
next if -d $file;
# Extra filtering, to copy only grib files ending in H
next unless $file =~ /H$/;
print "Doing $file\n" if $debug;
my @lines = ();
open IN, "+<$Grib_dir/$file" or die "open '$file': $! ($^E)";
binmode IN;
while (<IN>) {
s/nxny 5041 \d{4}/nxny 5041/g;
s/nx \d{4}/nx 71/g;
s/ny 1/ny 71/g;
s/\(\d{4} x 1\)/\(71 x 71\)/g;
push @lines, $_;
}
seek IN, SEEK_SET, 0; # rewind file
print IN @lines;
close IN;
}
closedir DIR;
__END__
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs