Perl: Getting a script to accept arguments
Here is what I wrote so far:
#! /usr/bin/perl -w # match.pl system("clear"); print "Please enter a file to be searched: "; $file_searched = <STDIN>; chomp $file_searched; open (FILE1, $file_searched) || die "File not found.\n"; @line = <FILE1>; close FILE1; print "What text pattern do you want to search for? "; $pattern = <STDIN>; chomp $pattern; $line_number = 1; foreach $line (@line) { if($line =~ m/$pattern/g) { print "Found another \"$pattern\" at Line Number: $line_number.\n"; } $line_number++; } exit 0; END OF CODE What can i do to add to this that will accept an option like this: ./match.pl filename search_string ???? |
Well, you need to use the @ARGV array.
Alex |
probably want Getopts in there too if it gets more complex.
|
Quote:
|
It's just an already-existing global variable.
Alex |
ok, ok... now really...
what would this code look like? :-) |
@ARGV is just an array of the arguments passed to the program (which I can't be bothered to write for you just now; someone else might). There's a lot of freely available documentation on these kinds of Perl basics, not least the comprehensive man page documentation that comes with Perl.
Alex |
sounds a lot like an RTFM to me, JStew! :D
|
yeah, it is acid-- i really tried to disguise it as best i could but, you know ignorance... hard to conceal it at times :-)
|
yeah, that and old age are a bad combination i guess.....
|
<grumble> well, thanks a lot acid ... you killed the thread! </grumble>
|
All times are GMT -5. The time now is 04:13 PM. |