URL: https://www.opennet.me/cgi-bin/openforum/vsluhboard.cgi
Форум: vsluhforumID9
Нить номер: 2753
[ Назад ]

Исходное сообщение
"Как открыть файл?"

Отправлено Sergey , 05-Апр-04 13:48 
Добрый день.
Такая проблемка со скриптом:
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. Как его открыть, чтобы сначала считать, а затем перезаписать?

Содержание

Сообщения в этом обсуждении
"Как открыть файл?"
Отправлено Simps , 06-Апр-04 13:42 
>Добрый день.
>Такая проблемка со скриптом:
>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;


"Как открыть файл?"
Отправлено Sergey , 06-Апр-04 20:22 
>>Добрый день.
>>Такая проблемка со скриптом:
>>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.
Если открывать +> содержимое файла сразу удаляется, без чтения.


"Как открыть файл?"
Отправлено alchie , 07-Апр-04 02:58 
>Еще с cron помучился, понимает только абсолютные пути, даже для sendmail.

для этого в кронтаб можно добавить строку

PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin