Adding a line in a file inside many directories



Hi all,
I am a beginer in PERL.
What I am trying to do is this:
I have a 150 directories, each having a file "kat.s" in them.
I have names of all these directories in a text file
"list_of_dir.txt".

I have to open the each of "kat.s" in all the 150 directories and add
a line(say "ABCD" at line number 20) in each of them.

What I have thought of doing is that using "list_of_dir", open each
directory and open kat.s and print the required statment.
I have written a code. But I am stuck in opening the directory and
than kat.s file.
Please help.
(Or suggest any better way to do it)

Thanks.

#######
use strict;
use warnings;


my $file = 'print.txt';
open my $VEDOUT, '>', $file or die "Could not open '$file': ";


open (VEDIN, 'list_of_dir.txt') or die "Cannot open 'File.txt' $!";
my @rgstr=<VEDIN>;

foreach my $file_list (@rgstr) {
print $file_list ; #printing list of dir

open (dirIN, '$file_list/kat.s') or die "Cannot open 'File.txt' $!";
#This is not working

}
close (VEDIN);
close ($VEDOUT);

#########

.



Relevant Pages

  • Adding a line in a file inside many directories
    ... I am a beginer in PERL.(I have posted this message in perl.beginers ... also and is with moderators) ... foreach my $file_list (@rgstr) { ...
    (comp.lang.perl.misc)
  • parse hash by array element seems to run slow
    ... I've been through the faq's and every web site that focuses on perl ... I iterate the array and search the hash keys to find a match and then ... foreach $verifyArr ...
    (comp.lang.perl.misc)
  • Perl crash related to Tie::File and hashes
    ... crash in perl when I try to use the data later on. ... sub TIEARRAY { ... foreach my $p { ... The assignment in the last loop causes perl to crash. ...
    (comp.lang.perl.moderated)
  • Re: Search and replace problem
    ... the foreach part doesn't work. ... You are not using the natural representation of things. ... string, it's a precompiled regex. ... Why not just write Perl? ...
    (comp.lang.perl.misc)
  • Re: The huge amount response data problem
    ... Perl is well suited to programming with multiple threads (or ... my $reqs = [ ... foreach { ... sub format_html { ...
    (comp.lang.perl.misc)