Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

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


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
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-25 12:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found