in reply to searching several files for a string at one time

Hey, update here This is how far I've got so far

#!/usr/bin/perl use strict; use warnings; my $directory = 'C:\Users\Anthony\music'; opendir (DIR, $directory) or die $!; while (my $file = readdir(DIR)) { print "$file\n"; } closedir(DIR);

This lets me open any directory, but how do I make it so the users can select the directory when the programme is ran? Also, I found this code, whcih appears to do what I want, but I can't seem to merge it with what I already have

$ grep "redeem reward" /home/tom/*.txt

Replies are listed 'Best First'.
Re^2: searching several files for a string at one time
by toolic (Bishop) on May 06, 2010 at 19:39 UTC
    but how do I make it so the users can select the directory when the programme is ran?
    One way is to pass it in on the command line (see shift):
    use strict; use warnings; my $directory = shift; print "dir=$directory\n"; # just for debug

    Run your program as:

    $ ./838783.pl /foo/bar dir=/foo/bar
      I tried the first paragraph of code
      use strict; use warnings; my $directory = shift; print "dir=$directory\n"; # just for debug
      I got this error use of uninitilised value $directory in concatenation (.)or string at.......... sayingline 6 fault in code, but dont know why... bah this stuff confuses me Do I add the code you posted to the code I already have or is it stand alone? If so, what did you mean by run my file as the second bit of code?