On Tue, 30 Dec 2003 19:07:26 -0800
"Perl" <[EMAIL PROTECTED]> wrote:
> I have a problem with the following block of code. It works fine when
> there isn't a *.log file in the same directory as the script but when
> there is, it always returns that log as the newest file and ignores the
> list of files it retrieves from the remote server.
>
> I debugged this and found that the READDIR is working but the last
> element in the list is the log file that is in the script directory.
>
> What can I do to make sure I get the list of *.log files on the remote
> machine regardless of what exists in my working local directory?
> $iisdir = '\\\server01\c$\winnt\system32\logfiles\W3SVC1';
> opendir LOGS, "$iisdir" or die "Directory error for IIS LOGS: $!\n";
>
> my @files = grep /\.log$/, readdir LOGS;
> @files = sort { -M $a <=> -M $b } @files;
> $active_log = $files[-1]; # this should be the newest file rather
instead of the above three lines, try
@files = sort {-M $b <=> -M $a } grep -f,<$iisdir/*.log>;
#in windows that might have to be grep -f,<$iisdir\*.log>
$active_log = $files[-1];
That ensures you are reading the directory
Are you using the -w switch? if not do so as it will report warnings which should give
you clues as to why it is not working.
You wont have to do the opendir bit then
--
Owen
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>