ocehb: (Default)
[personal profile] ocehb
имеется файл с текстом, разделенном на абзацы.

необходимо читать текст поабзацно, и если в первой стоке абзаца встречается некое слово, то записывать его в файл-1, если другое — то в другой, etc.



use IO::File;

my $io = new IO::File shift;
my %h = @ARGV;

local $/ = "";

while (<>) {
    foreach my $h (keys %h) {
        next unless (m#\A.*?$h#m);
        ref $h{$h} eq "IO::File" or $h{$h} = new IO::File "> $h{$h}";
        $h{$h}->print ($_);
        last;
    }
}


использование:


# perl script file "Jane" file1 "Mike" file2 "OCEHb" file3

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org

Profile

ocehb: (Default)
ocehb

January 2021

S M T W T F S
     12
345 6789
10111213141516
17181920212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 7th, 2026 04:38 am
Powered by Dreamwidth Studios