in reply to Re: Removal of duplicated element in array.
in thread Removal of duplicated element in array.

I tried  my @match_to_array = split (/\n/,$match); , the  \n are not preserved.

my @r = keys { map { $_ => 1 } split /\n/, $match }; has " Type of arg 1to keys must be hash (not annonymous hash ) " error.

Guess I did something wrong for the -rep ? Sorry If I did so.

Replies are listed 'Best First'.
Re^3: Removal of duplicated element in array.
by hdb (Monsignor) on May 06, 2013 at 15:02 UTC

    Might be that you are using an older version of Perl? I'm on 5.16. Here is a two line version:

    my %seen = map { $_ => 1 } split /\n/, $match; my @r = keys %seen;

    Hope this now works for you. And I still assume that you want to get rid of the \n? Apologies for any confusion I caused.

      Yup, I am using Perl v5.10.1 .

      The \n is simply for readability purposes, so if it isn't there, it is still alright.

      The output of your code outputs the same result as the input with duplicates.