Re: Adding a line in a file inside many directories



Ved wrote:
Joe I tried the code. This is what it is returning
######
File green_mcs020 /kat.s does not exist; skipping
File green_mcs0_40 /kat.s does not exist; skipping
File green_mcs0_20L /kat.s does not exist; skipping
File green_mcs0_40_20U /kat.s does not exist; skipping
#######

I think it is because the whitespace between the directory and file.

Directory file
green_mcs020(whitespace)/kat.s

Am I right ?

Sounds plausible...

I did some chomp in the code but it didn't help. From where this
whitespace is coming in ?

Maybe the file is corrupt. Try to run this from command line:

perl -pi -e 's/\s+$/\n/' my.tests

It should remove redundant trailing whitespace.

After adding chomps code looks like this now :

#!/usr/local/bin/perl
use strict;
use warnings;

my $dir_list = 'my.tests';
chomp $dir_list ; ## added by me
my $file_to_change = 'katana.sv';
chomp $file_to_change ; ## added by me

Please do not just do "some chomp". It's obvious that you don't know what that function does, so you'd better check the applicable docs:

perldoc -f chomp

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.



Relevant Pages