Skip to main content
accept most edits by @Alex and clean up a few other things
Source Link
Wes Hardaker
  • 22.3k
  • 2
  • 42
  • 70

A better solution is to use readdir() instead (or File::Find if you ever want to do it recursively):

my $dir = "C:\\SomeFiles"; my @flist;  opendir(my $dh, "$dir"$dir) || die "$!"; while (my $file = readdir($dh)) { if ($_$file =~ /.*(\\.txt)$txt$/i) {   print $file;  $file . "\n";  my $txt = do {   local $/ = undef;   open(my $ff, "<", "$dir\\$file") || die "$!";   <$ff>;   };   print substr($txt, 0, 100); . "\n"; } } closedir($dh); 

A better solution is to use readdir() instead (or File::Find if you ever want to do it recursively):

my $dir = "C:\\SomeFiles"; my @flist;  opendir(my $dh, "$dir") || die "$!"; while (my $file = readdir($dh)) { if ($_ =~ /.*(.txt)$/i) {   print $file;  my $txt = do {   local $/ = undef;   open(my $ff, "<", "$dir\\$file") || die "$!";   <$ff>;   };   print substr($txt, 0, 100); } } 

A better solution is to use readdir() instead (or File::Find if you ever want to do it recursively):

my $dir = "C:\\SomeFiles"; opendir(my $dh, $dir) || die "$!"; while (my $file = readdir($dh)) { if ($file =~ /\\.txt$/i) { print $file . "\n";  my $txt = do { local $/ = undef; open(my $ff, "<", "$dir\\$file") || die "$!"; <$ff>; }; print substr($txt, 0, 100) . "\n"; } } closedir($dh); 
remove pipe
Source Link
Wes Hardaker
  • 22.3k
  • 2
  • 42
  • 70

A better solution is to use readdir() instead (or File::FindFile::Find if you ever want to do it recursively):

my $dir = "C:\\SomeFiles"; my @flist; opendir(my $dh, "$dir |""$dir") || die "$!"; while (my $file = readdir($dh)) { if ($_ =~ /.*(.txt)$/i) { print $file; my $txt = do { local $/ = undef; open(my $ff, "<", "$dir\\$file") || die "$!"; <$ff>; }; print substr($txt, 0, 100); } } 

A better solution is to use readdir() instead (or File::Find if you ever want to do it recursively):

my $dir = "C:\\SomeFiles"; my @flist; opendir(my $dh, "$dir |") || die "$!"; while (my $file = readdir($dh)) { if ($_ =~ /.*(.txt)$/i) { print $file; my $txt = do { local $/ = undef; open(my $ff, "<", "$dir\\$file") || die "$!"; <$ff>; }; print substr($txt, 0, 100); } } 

A better solution is to use readdir() instead (or File::Find if you ever want to do it recursively):

my $dir = "C:\\SomeFiles"; my @flist; opendir(my $dh, "$dir") || die "$!"; while (my $file = readdir($dh)) { if ($_ =~ /.*(.txt)$/i) { print $file; my $txt = do { local $/ = undef; open(my $ff, "<", "$dir\\$file") || die "$!"; <$ff>; }; print substr($txt, 0, 100); } } 
Source Link
Wes Hardaker
  • 22.3k
  • 2
  • 42
  • 70

A better solution is to use readdir() instead (or File::Find if you ever want to do it recursively):

my $dir = "C:\\SomeFiles"; my @flist; opendir(my $dh, "$dir |") || die "$!"; while (my $file = readdir($dh)) { if ($_ =~ /.*(.txt)$/i) { print $file; my $txt = do { local $/ = undef; open(my $ff, "<", "$dir\\$file") || die "$!"; <$ff>; }; print substr($txt, 0, 100); } }