如何删除重复的#include指令?

Ad-*_*vic 0 perl hash

#include <stdint.h>
#include <stdlib.h>
#include <VideoInChain.h>
#include <VideoOutChain.h>
#include <stdint.h>
#include <stdlib.h>
...//rest of code
Run Code Online (Sandbox Code Playgroud)

有系统头文件重复我需要删除而不影响其余的代码

我试过了

sub uniq {
  my %seen = ();
  my @r = ();
  foreach my $a (@_) {
     unless ($seen{$a}) {           
         push @r, $a;
         $seen{$a} = 1;
      }
    }
  return @r;
  }
  @lines_temp = uniq(@lines_temp);
Run Code Online (Sandbox Code Playgroud)

但它删除了所有类型的重复,包括'(','{'和空格

我只需要删除重复的系统文件

Сух*_*й27 6

sub uniq {
  my %seen;
  my @r;
  for my $a (@_) {
     my ($m) = $a =~ /#include\s+<(.+?)>/;
     push @r, $a if !$m or !$seen{$m}++;
  }
  return @r;
}
@lines_temp = uniq(@lines_temp);
Run Code Online (Sandbox Code Playgroud)

要么

sub uniq {
  my %seen;
  return grep {
     my ($m) =~ /#include\s+<(.+?)>/;
     !$m or !$seen{$m}++;
  } @_;
}
@lines_temp = uniq(@lines_temp);
Run Code Online (Sandbox Code Playgroud)

或者oneliner,

perl -ne '($m) = /#include\s+<(.+?)>/; print if !$m or !$s{$m}++' file
Run Code Online (Sandbox Code Playgroud)