You could do at least two things:
1) Introduce additional command-line arguments, allowing the user to specify a pattern to search for on the command line when invoking the script. Depending on the size of your input file(s) and on the number of searches you want to perform on each, this may be inefficient.
If you do want to do this, and if you eventually want to add more options, you could look into the Getopt family of modules, e.g. Getopt::Std or Getopt::Long.
2) Add a loop where you present a prompt, read a pattern from STDIN and then search for that, something along the lines of the following:
while(1) { print "Enter a pattern to search for, or QUIT to quit >"; $_ = <STDIN>; m/^QUIT$/ and exit(0); search_for_pattern($_); }
With a suitable search_for_pattern(), of course. HTH!
In reply to Re: Searching for strings specified via user input
by AppleFritter
in thread Searching for strings specified via user input
by TJCooper
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |