On Fri, Jul 16, 2010 at 17:43, perl_learner <rahma...@gmail.com> wrote: > Hi, > > #!/usr/bin/perl > #!/usr/bin/perl -w > > my @result=`find ../src -name '*Msgs.msg'`; > #print "MSG direictories are: $result[0]"; > > foreach my $res (@result) { > print "$res"; #prints the array value of result > } > > I have the array value as: > > ../src/libfile/src/FileRealMsgs.msg > ../src/libl/src/RRLRealMsgs.msg > ../src/libg/src/SSRealMsgs.msg > ../src/libt/src/TTRealMsgs.msg > ../src/libl/src/UURealMsgs.msg > ../src/libpl/src/VVMsgs.msg > > Question: > > From avobe output for each line I need to "cd to that directory and do > some task". > > Example: from above output, I need to "cd ../src/libfile/src"; "do > some task"; again enter to next direcotry and so on. snip
The [chdir][0] function will change the directory for the Perl script, but you may be better served by using the [File::Find][1] module as it rolls the find command and the chdir into one function: #!/usr/bin/perl use strict; use warnings; use File::Find; find sub { return unless /Msgs[.]msg$/; print "found $File::Find::name\n"; #you are now in the directory where the file was found #do whatever you want }, "../src"; [0]: http://perldoc.perl.org/functions/chdir.html [1]: http://perldoc.perl.org/File/Find.html -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/