in reply to Reading Directory and getting pattern from a file

~/directory /subdir1 /report file.txt /subdir2 /report anotherfile.txt ... /subdir130 /report yetanotherfile.txt

Is this a correct idea of the files and directory structure? File::Find, as suggested, will navigate among the subdirectories. No idea what you mean by "grab a pattern".

If this is homework, it's best to say so up front.

Dum Spiro Spero

Replies are listed 'Best First'.
Re^2: Reading Directory and getting pattern from a file
by Eshan_k (Acolyte) on Feb 10, 2015 at 17:34 UTC
    Hello Dum Spiro Spero, The structure you showed is correct. I know how to get pattern string from that file. To be honest it is related to my work and I got stuck at point. Can you please show a sample code. I would really appreciate your help. Again thanks for replying to my post.

      What do you have so far? Look at the examples provided with File::Find, and you can find others via Google and on this site.

      By the way, "Dum Spiro Spero" is not my name, just a tagline. It means "while I breathe, I hope" in Latin.

      Dum Spiro Spero
        Sorry I was not aware its not your name and yes tag line is cool. So far I have this much. code, I want to go into subdirectories from there. and "mdp" is a pattern I want to match. Power artist has directories and in those there are several sub directories I just want to traverse and get the line from the file in those sub-directories. ---------------------------------------- 1 #!usr/bin/perl; 2 3 use strict; 4 use warnings; 5 6 7 $| = 1; 8 9 10 sub main{ 11 12 my $directory = '/nfs/fm/stod/stod1031/w.eakanoje.101/power_artist_2/'; 13 opendir (DIR, $directory) or die "Cannot open directory $directory"; 14 # while (my $file = readdir(DIR)){ 15 # next if($file =~ m/^\./); 16 # print "$file\n"; 17 # } 18 19 my @out = glob("mdp*"); 20 21 print "@out\n";

        Sorry, I was not aware of your name. Your tag line is cool. :) So far I have written this much of code. The power directory has two directories and in those directories. There are 130 sub directories for each directories. I want to go to each sub directory and get a pattern from a text file in that directory. I am stuck with how to check directories and get that perticular pattern. mdp is a pattern. Your help will be greatly appreciated.

        #!usr/bin/perl; use strict; use warnings; $| = 1; sub main{ my $directory = '/nfs/fm/stod/stod1031/w.eakanoje.101/power/'; opendir (DIR, $directory) or die "Cannot open directory $directory" +; # while (my $file = readdir(DIR)){ # next if($file =~ m/^\./); # print "$file\n"; # } my @out = glob("mdp*"); print "@out\n"; } main();
        ------------------------------------------