Paul Kraus wrote: > WTF now its working with no changes to the program...... > This is very frustrating. > Is perl some how looking at the way the directory was last > sorted in my > Ms window even though its pulling it from a UNIX server?
Perl isn't doing anything but calling the OS's underlying readdir(2) call. You shouldn't make any assumptions about the order in which readdir() returns files. If you need them in some particular order, read them and then sort them. > > -----Original Message----- > From: Paul Kraus [mailto:[EMAIL PROTECTED] > Sent: Friday, August 22, 2003 2:30 PM > To: [EMAIL PROTECTED] > Subject: Read dir / sort > > > I have a program that would read a directory and then do some > renaming. Up until recently it always seem to read by oldest file > first > to newest. > Which is great because my renaming involves incrementing a counter and > placing that count in each file. So if the order was changed > the program > will break. Which it did. > > So two questions why is it reading the directories different now? How > can I have it read the directory with oldest file first. > > Here is the sub routine. > > sub getfiles { > my ($amcount, $pmcount); > opendir ( DH, '//sco1/pm6/reports') or die ("Can not open > directory\n"); foreach ( readdir (DH) ) { > next unless /^Sj/; > print "$_\n"; > #&changefilename( ( stat( "//sco1/pm6/reports/$_" ) ) [9], $_ ); > } die; > foreach (keys %files){ > my $counter; > foreach ( @ { $files {$_} } ) { > $counter++; > $_->[1] =~ s/_/_($counter)_/; > print "$_->[1]\n"; > # rename "//sco1/pm6/reports/$_->[0]", "./$_->[1]" or die ( "NO! > $!\n" ); } > } > } > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]