我已經學會了如何使用下面的代碼以消除重複的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 2009-10-24 06:19:04