Debbie Cooper wrote on 25.05.2004:
>I need to search for the occurrence of a string in a file that is
>buried in directories. So, for example, I have a directory
>structure that looks like this C:\data\elec\1\220\webdata.tab. The
>last three folders change frequently so I can have
>c:\data\appl\3\180\webdata.tab and so on. The file I'm searching
>will always be called webdata.tab. It is a tab delimited file with
>headers and I need to search the header for a specific word like
>"Brand" and somehow return the directory structure where the word is
>found. Can this be done in "beginning" perl?
>
Sure. Make use of File::Find to traverse the directory structure. For each file, you
will have the whole path in the $File::Find::name variable. You could do something like
use File::Find;
find(\&wanted, @directories_to_search);
sub wanted {
if $File::Find::name =~ /webdata.tab/ {
# open the file and look for the header
# return a message including the $FIle::Find::name if the header is found
}
}
HTH,
Jan
--
If all else fails read the instructions. - Donald Knuth
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>