Get best price on Prepaid Samsung Galaxy A10e | ||||||||||||
|
||||||||||||
|
Perl : SubDir RecursionA great use of Perl is for small utility scripts. Two utility scripts that I have written are a LowerCase script, which renames all the files in a directory and its subdirectories to all lowercase, and an Include script, which recurses through all HTML files in a directory searching for an include tag and inserts the appropiate files. Both of these are used to maintain this or other web sites, and both of these scripts use a very handy Perl module called File::Recurse. The File::Recurse module was written by Aaron Sherman and can be download at any CPAN site. The module is bundled with the File-Tools-2.0 module which can be downloaded from the CPAN site here (/modules/by-module/File/). The module works on both UNIX and Win32 systems running Perl. The module allows you to perform a function on all files/dir inside of a specified directory. It recurses through all the subdirectories automatically performing the specified function on each file. Here an example program which will lowercase all files in a specified directory. It reads in the directory through the command-line when you execute the script.
use File::Recurse;
# read in directory $dir = $ARGV[0]; # verify directory if (-d $dir) { print "Working Directory: $dir\n"; } else { print "\nError: Directory Not Found $dir\n"; exit(0); } # call recurse function from module # this applies the sub-routine lcName to all files # in the specified directory recurse(\&lcName, $dir); # define the lcName sub-routine which lowercases all files sub lcName { # receive passed filename $filename = $_[0]; $newfilename = $filename; # regexp that converts to lowercase $newfilename =~ tr/A-Z/a-z/; # if I can read and write to it # rename the filename to the lowercase one if ((-r $filename) && (-w $filename)) { rename($filename, $newfilename); print " Renamed: $filename to $newfilename\n"; } } Related Links:
|
privacy policy || © 1997-2016. astonishinc.com All Rights Reserved. |