in reply to Removal of duplicated element in array.

One issue are the parantheses in split("(\n)",$match). They preserve the delimiters \n as part of your array and are also present in the final result @r. Try

split /\n/, $match

instead. You can also do it as a one-liner:

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

UPDATE: I mean the parantheses in "(\n)", not the outer ones.

Replies are listed 'Best First'.
Re^2: Removal of duplicated element in array.
by tty1x (Novice) on May 06, 2013 at 14:54 UTC
    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.

      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.
Re^2: Removal of duplicated element in array.
by tty1x (Novice) on May 06, 2013 at 14:36 UTC
     /\n/ doesn't preserve the delimiters =X .