Re: directory operations
MuthuKumar wrote: Hello All, I have a directory which contains several files.. like .txt .html .js files like that. I have to search a pattern in all files.. if it is available then replace it and else leave it out. I have made it for single file.. what i want is to implement for the full directory.. my @file_list = /*.txt/ foreach $file (@file_list){ file loop snip. close(file-handle); } I have checked like this.. i did not get any response at all.. No files are stored in the array too. what is wrong with this.. and how to accomplish this. -- Regards, Muthukumar. You need to change the line: my @file_list = /*.txt/ to my @file_list = *.txt or my @file_list = glob *.txt -- Flemming Greve Skovengaard FAITH, n. a.k.a Greven, TuxPower Belief without evidence in what is told [EMAIL PROTECTED] by one who speaks without knowledge, 4168.08 BogoMIPS of things without parallel. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: directory operations
MuthuKumar wrote: Hello All, I have a directory which contains several files.. like .txt .html .js files like that. I have to search a pattern in all files.. if it is available then replace it and else leave it out. I have made it for single file.. what i want is to implement for the full directory.. my @file_list = /*.txt/ foreach $file (@file_list){ file loop snip. close(file-handle); } I have checked like this.. i did not get any response at all.. No files are stored in the array too. what is wrong with this.. and how to accomplish this. my @file_list = *.txt; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: directory operations
If you did want to filter based on a regular expression, you can always do it the long way: opendir(DIR,.) || die; my @file_list = readdir(DIR); foreach my $file(@file_list){ if(-f $file ($file =~ /Place Regex Here/)){ #do something... } } You get the general idea. Also, if you want to do a recursive search, look into the standard File::Find module. -Original Message- From: Randy W. Sims [mailto:[EMAIL PROTECTED] Sent: Thu 4/1/2004 2:02 AM To: MuthuKumar Cc: [EMAIL PROTECTED] Subject: Re: directory operations [snip] my @file_list = /*.txt/ foreach $file (@file_list){ file loop snip. close(file-handle); } I have checked like this.. i did not get any response at all.. No files are stored in the array too. what is wrong with this.. and how to accomplish this. my @file_list = *.txt;