MikeDexter has asked for the wisdom of the Perl Monks concerning the following question:
My script runs without error but is not making changes to the files that it finds.
And, there are two lines in the master file and it appears the loop is not getting to the second line.
And, it is not renaming any files to .bak
MY OUTPUT#!/usr/bin/perl use strict; use warnings; use File::Find; my $opsys = $^O; my $hostname = qx |uname -a| or die("Can't get info for hostname: $!\n +"); my @uname = split (/\s/, $hostname); my $searchdir = '/dir/etc-test'; print ">>> Operating System: $opsys" . "\n"; print ">>> Hostname: $uname[1]\n"; open (my $FH, '<', 'ipmastr') or die "Could not open 'ipmaster' : $!"; + while (<$FH>){ chomp; my ($ipold, $ipnew, $nmold, $nmnew, $dgold, $dgnew, $ns1old, $ns1n +ew, $ns2old, $ns2new, $ip6old, $ip6new) = split (/\t/); $^I = '.bak'; find(\&wanted, $searchdir); sub wanted { my $filename = $File::Find::name; print "$ipold - Filename is: $filename\n"; return unless -f $filename; open (FR, '<', '$filename') or print "Could not read $filename +\n" && return; my @lines = <FR>; close (FR); open (FW, '>', '$filename') or print "Could not open for write + $filename\n" && return; for ( @lines ) { s/$ipold/$ipnew/g; print FW $_; } close FW; } } close $FH;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need assistance updating text files with Perl
by Anonymous Monk on Dec 31, 2009 at 17:15 UTC | |
|
Re: Need assistance updating text files with Perl
by MidLifeXis (Monsignor) on Dec 31, 2009 at 18:18 UTC | |
by Anonymous Monk on Dec 31, 2009 at 18:25 UTC | |
by Anonymous Monk on Dec 31, 2009 at 18:43 UTC | |
by MikeDexter (Sexton) on Dec 31, 2009 at 19:29 UTC | |
|
Re: Need assistance updating text files with Perl
by Marshall (Canon) on Jan 01, 2010 at 01:33 UTC |