다음 코드를 사용하여 Perl에서 중복을 제거하는 방법을 이미 배웠습니다.Perl을 사용하여 겹치는 요소를 어떻게 병합 할 수 있습니까?
my %seen =();
my @unique = grep { ! $seen{ $_}++ } @array;
그러나 겹치는 부분을 병합하려면 어떻게해야합니까? 위의 코드가 작업을 직접 수행하는 간단한 방법이 있습니까?
예를 들어, 입력 파일의 일부는 다음과 같습니다.
Anais Nin : People living deeply have no fear of death. Pascal : Wisdome sends us back to our childhood. Nietzsche : No one lies so boldly as the man who is indignant. Camus : Stupidity has a knack of getting its way. Plato : A good decision is based on knowledge and not on numbers. Anais Nin : We don't see things as they are, we see them as we are. Erich Fromm : Creativity requires the courage to let go of certainties. M. Scott Peck : Share our similarities, celebrate our differences. Freud : The ego is not master in its own house. Camus : You cannot create experience. You must undergo it. Stendhal : Pleasure is often spoiled by describing it.
원하는 결과는 다음과 같습니다.
Anais Nin : People living deeply have no fear of death. We don't see things as they are, we see them as we are. Pascal : Wisdome sends us back to our childhood. Nietzsche : No one lies so boldly as the man who is indignant. Camus : Stupidity has a knack of getting its way. You cannot create experience. You must undergo it. Plato : A good decision is based on knowledge and not on numbers. Erich Fromm : Creativity requires the courage to let go of certainties. M. Scott Peck : Share our similarities, celebrate our differences. Freud : The ego is not master in its own house. Stendhal : Pleasure is often spoiled by describing it.
언제나처럼 모든 안내에 감사드립니다!
왜 downvote? 내 질문에 올바른 표현 방법은 무엇입니까? 감사. – Mike