>>Добрый день.
>>Такая проблемка со скриптом:
>>open(DB, "+<$dbfile")||die "Can\'t open $dbfile, $!";
>>while (<DB>)
>>{
>>-----
>>-----
>>push (@acc,$username," ",$host," ",$address," ",($traf+$totalsize),"\n");
>>}
>>seek (DB,0,0);
>>print DB @acc;
>>Файл читается, но не перезаписывается, права 666. Как его открыть, чтобы сначала
>>считать, а затем перезаписать?
>
>+< открывает на чтение
>
>
> If MODE is "'<'" or nothing, the file
>is opened for input. If
> MODE is "'>'", the file is truncated and opened for output,
> being created if necessary. If MODE is "'>>'", the file is
>
> opened for appending, again being created if necessary.
> You
> can put a "'+'" in front of the "'>'" or "'<'" to indicate that
>
> you want both read and write access to
>the file; thus "'+<'" is
> almost always preferred for read/write updates--the "'+>'" mode
>
> would clobber the file first. You can't
>usually use either
>
> read-write mode for updating textfiles, since they have
>vari-
>
> able length records. See the -i switch
>in the perlrun manpage
>
> for a better approach. The file is
>created with permissions of
>
> "0666" modified by the process' "umask" value.
>Вам надо +>
>open (OTCH,"+>file.txt);
>print OTCH "Shit\n";
>close OTCH;
Спасибо за участие, ошибку нашел, лишний "\n" писал в файл и при следующем запуске скрипта обрабатывалась пустая строка и все портила.
Еще с cron помучился, понимает только абсолютные пути, даже для sendmail.
Если открывать +> содержимое файла сразу удаляется, без чтения.
|