Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Perl Monk, Perl Meditation
 
PerlMonks  

Re: How do I read the contents of each file in a directory?

by gube (Parson)
on Mar 28, 2006 at 23:49 UTC ( [id://539872]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to How do I read the contents of each file in a directory?

#!/usr/local/bin/perl use strict; opendir(DIR, "."); my @files = grep/^\w+/, readdir(DIR); for (@files) { undef $/; open(IN, "$_") || die "Cannot open $_"; my $str = <IN>; print $str; close(IN); }

If you need to read only text file you can grep only .txt file. For eg: my @files = grep/.txt$/, readdir(DIR);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://539872]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.