File: sortdw.pl

package info (click to toggle)
tucnak 4.67-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 32,932 kB
  • sloc: ansic: 87,491; sh: 8,857; perl: 516; makefile: 416; xml: 21
file content (39 lines) | stat: -rwxr-xr-x 676 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/perl -w

open(F, "tucnakdw") or die;
open(G, ">tucnakdw.tmp") or die;

while ($s=<F>){
    $s=~s/[\r\n]+//;
    if ($s=~/^#/) {
        print G "$s\n";
        next;
    }
    if ($s=~/^\s*$/) {
        print G "$s\n";
        next;
    }
    print G "$s\n";
    
    $s=<F>;
    $s=~s/[\r\n]+//;
    die "empty second line" if (!defined($s));
    @a=split(/\s+/, $s);
    %a=();
    foreach $a (@a) {$a{$a}=1;}
    @a=sort(keys(%a));
    $s=join(" ", @a);
    print G "$s\n";
    
    $s=<F>;         #can be empty string
    if (defined($s)){
        $s=~s/[\r\n]+//;
        print G "$s\n";
    }
    
}

close(F);
close(G);

rename("tucnakdw.tmp", "tucnakdw");