Hi John,

Thanks for your reply.

On Jul 18, 6:48 pm, jwkr...@shaw.ca ("John W. Krahn") wrote:
> perl_learner wrote:
> > Hi,
>
> Hello,
>
>
>
>
>
> > #!/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.
>
> > Any help is appreciated.
>
> Something like this may work but it is UNTESTED:
>
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> use Cwd;
> use File::Find;
>
> my $current_dir = getcwd;
> my $search_dir  = '../src';
>
> my %working_dirs;
> find sub {
>      $working_dirs{ $File::Find::dir }++ if /Msgs\.msg\z/;
>      }, $search_dir;
>
> foreach my $dir ( keys %working_dirs ) {
>      chdir $dir or die "Cannot chdir to '$dir' $!";
>      do_some_task();
>      chdir $current_dir or die "Cannot chdir to '$current_dir' $!";
>      }
>
> __END__
>
> John
> --
> Any intelligent fool can make things bigger and
> more complex... It takes a touch of genius -
> and a lot of courage to move in the opposite
> direction.                   -- Albert Einstein- Hide quoted text -
>
> - Show quoted text -


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to