CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [mohan] Searching for a string: Edit Log



Tejas
User

Jan 27, 2015, 10:45 PM


Views: 35239
Re: [mohan] Searching for a string

Yes, it is possible.
Please follow Chris's post .

http://perlguru.com/gforum.cgi?post=79347;search_string=read%20files%20from%20a%20directory;#79347

You can do something like this


Code
use strict; 
use warnings;
my @files;
opendir(Dir, $Directoryname) or die "cannot open directory $Directoryname";
@files = grep(/\.txt$/,readdir(Dir));


All your filenames would a part of array @files.

to access them



Code
foreach $file (@files) { 
open my $handle, '<', $file or die "could not open '$file': $!";
while (my $line = <$handle>) {
#Your checks per line

}

}


The code pasted above is untested and probably would work as per ur requirements

Thanks
Tejas


(This post was edited by Tejas on Jan 27, 2015, 11:45 PM)


Edit Log:
Post edited by Tejas (User) on Jan 27, 2015, 10:52 PM
Post edited by Tejas (User) on Jan 27, 2015, 11:45 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives