kansal611 has asked for the wisdom of the Perl Monks concerning the following question:
it says/..............#!/usr/bin/perl -w use strict; my ($dir,$file,$old,$new); print "Enter Directory path: "; $dir = <STDIN>; print "Enter filename: "; $file = <STDIN>; print "Enter old pattern: "; $old = <STDIN>; print "Enter new pattern: "; $new = <STDIN>; chomp ($dir,$file,$old,$new); opendir (DIR, "$dir") || die $!; my @files = readdir(DIR); foreach my $filename( @files) { if ("$file" =~ "$filename") { open (FH, "$file") || die "cant open file $!"; my @lines = <FH>; print @lines; foreach (@lines) { if (grep /"$old"/, $_) { s/"$old"/$new"/g; print $_; }} }}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: reading file in directory
by GrandFather (Saint) on Jan 27, 2011 at 07:15 UTC | |
|
Re: reading file in directory
by Ratazong (Monsignor) on Jan 27, 2011 at 07:32 UTC | |
|
Re: reading file in directory
by kansal611 (Initiate) on Jan 27, 2011 at 09:27 UTC |