in reply to Perl script does not work on other directories?
I think you want to use chdir to change into the directory you want.
Using opendir, you can do like so:
I also think, it would be great if you can open the files one after the other immediately and check for desired string.use warnings; use strict; print "Enter a directory:"; chomp( my $dir = <STDIN> ); print "String looked for: "; chomp( my $str = <STDIN> ); chdir $dir or die $!; opendir DH, $dir or die $!; while ( readdir(DH) ) { next if $_ eq '.' or $_ eq '..'; unless (-d) { open my $fh, '<', $_ or die $!; while (<$fh>) { print $_ if /\Q$str/; last; } } } closedir DH or die $!;
If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me
In Section
Seekers of Perl Wisdom