#!/usr/local/bin/perl
opendir DH, "Sanjay" or die "fail" ;
while($temp = readdir(DH)) {
print "$temp\n";
open FILE, "$temp" or die "fail";
print "pass";
while(<$temp>) {
print "sucess";
}
}
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
my $CurrentDir="."; # Or "Sanjay";
opendir DH, "." or die "failed to readdir $CurrentDir: $!";
while($temp = readdir(DH)) {
print "$temp\n";
if ($temp eq "." or $temp eq ".." or -d $temp){
next; # Do not open . or ..
}
open FILE, "$CurrentDir/$temp" or die "failed to open file $temp:$!\n";
print "pass";
while(<$temp>) {
print "sucess: $_";
}
}
Normally - I would not code this way - this is written to help you get past initial roadblocks.
"For every complex problem, there is a simple answer ... and it is wrong." --H.L. Mencken
#!/usr/local/bin/perl
use strict;
opendir(DIR, ".");
my @files = grep/^\w+/, readdir(DIR);
for (@files) {
undef $/;
open(IN, "$_") || die "Cannot open $_";
my $str = ;
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);
perlmonks.org content © perlmonks.org and gube, merlyn, mk., NetWallah, sanjaysingh
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03