So if we make the previous example a bit more generic, allowing it to get the search pattern and file name from the command line, it will behave almost exactly like the grep utility:
open MYFILE, $ARGV[1] or die "Can't open $ARGV[1]: $! \n";
while (<MYFILE>) {
if (/$ARGV[0]/) { print "MATCH: $_"; }
}
Learn More about Perl
We've barely scratched the surface of what you can do with the Perl language. Try the man perl command to get more information on Perl, read Programming Perl by Larry Wall (O'Reilly & Associates), the inventor of the Perl language, or visit the Perl Institute Web site at http://www.perl.org.
Previous Lesson: Perl and Files
Next Lesson: Sending Email
|
![]() |
|
| <Send This Link to a Friend> <Help> <Bookmark This Page> | ||