Next | Program Repair Shop | 18 |
Now let's have a look at GrabFileList for example:
113 sub GrabFileList { 114 opendir (FILELISTDIR1,$InputDIR1); 115 @FileList1 = readdir (FILELISTDIR1); 116 closedir (FILELISTDIR1); 117 opendir (FILELISTDIR2,$InputDIR2); 118 @FileList2 = readdir (FILELISTDIR2); 119 closedir (FILELISTDIR2); 120 }
This becomes:
sub GrabFileList { for my $dir (@InputDIR) { opendir (FILELISTDIR,$dir); push @FileList, map "$dir/$_", readdir FILELISTDIR; closedir FILELISTDIR; } }
7 lines become 5
Avoid families of variable names
Use a compound data structure instead; it's more flexible
Next | Copyright © 2002 M. J. Dominus |