By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,278 Members | 1,568 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,278 IT Pros & Developers. It's quick & easy.

Problem regarding mkdir and chdir and recursive function

P: 55
Hi All,
I have data in 20 different folders named from step_1...step_20 and each folder has some files which I am trying to manupulate and after that my program should make directories named step_1_results .... step_20_results and write each results into the respective directory. But somehow my code is not making directories and writing files INTO them instead writing them outside the directories.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4.  
  5. my $folder = "/home/r/surface_tension/";
  6. opendir(FO,$folder);
  7. my @fols = grep {/step_*/} readdir(FO);
  8. #print "@fols\n";
  9.  
  10. foreach my $foss(@fols)
  11. {
  12.     opendir(FOL,$foss);
  13.     my $folname = $foss;
  14.     #print "$foss\n";
  15.  
  16.    my @filess = grep {/\.out$/} readdir(FOL);
  17.     #for(my $i=0;$i<@filess;$i++)
  18.     #{
  19.         #print "$filess[$i]\n";
  20.     #}
  21.     foreach my $eva(@filess)
  22.     {
  23.         $name = $eva;
  24.         $name=~ s/\.out/.pmt/g;
  25.         print "$name\n";
  26.         `mkdir -p $foss_results`;
  27.          `cd $foss_results`;
  28.         open(WRITE,"$name_result");
  29.     }
  30.  
  31. }
  32.  
Thanks for Help
Kumar
Apr 15 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.