JDT |
John Dixon |
Using Perl and Regular Expressions to Process ASCII Files - Part 5 |
||||
|
In Part 1 we had a quick look at what Perl and regular expressions are, and introduced the idea of using them to process HTML files. In Part 2 we developed a Perl script to process a single HTML file. In part 3 we looked at one way of processing multiple files. In Part 4 we looked at how to read in all the files in the current directory. In this, the last part, we'll look at how to read in specific files in specific directories. In Part 4 we wrote a script that enabled us to read in all the files in the current directory. Sometimes, however, you might need to process files that are located in different directories. script4.pl lists a script that will do this. script4.pl
1 @allfiles=glob("file1.htm directory1/subdirectory1/*.shtm directory2/*.htm");
The only new line here is line 1, which uses the glob function to search through specified directories and files. Firstly, it searches for file1.htm in the current directory, and then it search for all files ending in .shtm in directory1/subdirectory1, and then all files ending in .htm in directory2. The asterisk (*) is a wildcard, which means any filename. Running the ScriptTo run the script, at the command line type: C:>perl script4.pl Author: John Dixon Go to Using Perl and Regular Expressions to Process ASCII Files - Part 1 Go to Using Perl and Regular Expressions to Process ASCII Files - Part 2 Go to Using Perl and Regular Expressions to Process ASCII Files - Part 3 Go to Using Perl and Regular Expressions to Process ASCII Files - Part 4 Go back to Perl Tutorials home page Go back to Tutorials home page
|
|
|
|||||
|
© 2007-2009 - John Dixon Technology Ltd |
|||||