Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· openaiHugging Face Suzhen/CodeChat

Как в Perl построчно прочитать и записать файл?

  1. User

    Как в Perl построчно прочитать и записать файл?

  2. Assistant

    Чтение файла построчно:

    open(FILE, "<file.txt") or die "Ошибка открытия файла: $!";
    
    while(<FILE>) {
        print $_;
    }
    
    close FILE;
    

    Запись файла построчно:

    open(FILE, ">file.txt") or die "Ошибка открытия файла: $!";
    
    print FILE "Первая строка\n";
    print FILE "Вторая строка\n";
    
    close FILE;
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.