Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

find a file in directory and do file processing

by Anonymous Monk
on Apr 06, 2006 at 13:34 UTC ( #541630=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a directory structure in which i have files like
LEAF.LINUX.LOG
LEAF.SOLARIS.LOG
test.asm
test.qo
Linux_Folder/
SOLARIS_Folder/
in the Linux_Folder(shown above ) again i have some files having same name as parent folder files.like
LEAF.LINUX.LOG
test.qrf
test.lis
similarly in the SOLARIS_Folder(shown above ) again i have some files having same name as parent folder files.like
LEAF.SOLARIS.LOG
test.qrf
test.lis
if i am in Linux_Folder i will look for LEAF_LINUX.log file and use same file from parent folder for doing I/O. similar for other folder. For this i wil try find LEAF*.LOG file in any folder, as there can be many log files in folder. this will give me LEAF_LINUX.log (or LEAF_SOLARIS.log). i tried using grep for LEAF*.log but i am unable to do it . how can i find LEAF*.log file and store it in a variable for future use.

Comment on find a file in directory and do file processing
Re: find a file in directory and do file processing
by sweetblood (Parson) on Apr 06, 2006 at 13:41 UTC
Re: find a file in directory and do file processing
by marto (Chancellor) on Apr 06, 2006 at 13:50 UTC
    Hi Anonymous Monk,
    A short example to get you started:
    #!/usr/bin/perl use strict; use warnings; use File::Find::Rule; my @filesfound = File::Find::Rule->file() ->name( 'LEAF*.LOG' ) ->in( "." ); foreach my $filename (@filesfound) { print "$filename\n"; }

    Should you need help installing modules, check out the Tutorials section of this site.

    Hope this helps.

    Martin

    Update: Changed .log to .LOG

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://541630]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2014-09-21 07:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (167 votes), past polls