-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 John W. Krahn wrote: >> #!/usr/bin/perl -w >> >> use strict; >> >> my @filenames; >> my $processDir = "/usr/bin"; >> >> opendir DH, $processDir or die "cannot open $processDir: $!"; >> foreach my $file (sort(readdir DH)){ >> push @filenames, $file; >> } > > Why not just: > > my @filenames = sort readdir DH; >
Being new to Perl I want to learn the "long" and traditional way before I begin figuring out all the shortcuts. Having been overwhelmed by all of the numerous options and possible methods of accomplishing this I took what I understood from everyone's suggestions and came up with this: #!/usr/bin/perl use warnings; use strict; my $processDir = "/usr/bin"; my @filenames; my $file_count = 0; opendir DH, $processDir or die "cannot open $processDir: $!"; foreach my $file (readdir DH){ next if ($file =~ /^\.]$|^\.\.$/); push @filenames, $file; } closedir DH; foreach my $filename (sort(@filenames)) { $filename = "$processDir/$filename"; my $mod_time = (stat($filename))[9]; print "$filename: $mod_time\n"; $file_count += 1; } print "\nThere are " . $file_count . " items in the filenames array.\n"; Dr. Ruud had mentioned that I was sorting too soon so I placed that in the second foreach loop. I corrected the match expression and prepended the directory to each file prior to running stat on it but didn't save the new value to the array. I was having a hard time understanding the - -f option and the line with grep in it so I didn't bother with those this time around. Perhaps I'll look into how to use them next time. Thanks everyone, for all you help. - -- Mathew -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFE6lzr7cEqtYW7kARAmQWAJ93Waa8rtdIc5JKvFt0FA0e1vYNiwCgqGxK esvk+quvbdkZU0gAjRjGZbY= =nN2c -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>