Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that I am trying to grab the unique values from. it does not do it. Any suggestions? Here is the code and input file:
@Deploy = <>; chomp(@Deploy); my @tmp = @Deploy; my %saw = (); foreach my $view_name (@Deploy) { print "view name is $view_name \n"; push (@Deploy1, $view_name) unless $saw{$view_name}++; } print join("\n",@Deploy1);
input file
\\test\test1\WEB\TEST/Admin*V:/test_viewINT/test_CVOB/test_src/Admin/A +dminMenu.asp" \\test\test1\WEB\TEST/Admin*V:/test_viewINT/test_CVOB/test_src/Admin/a +dminUser.asp" \\test\test1\WEB\TEST/Admin*V:/test_viewINT/test_CVOB/test_src/Admin/A +dminMenu.asp" \\test\test1\WEB\TEST/Admin*V:/test_viewINT/test_CVOB/test_src/Admin/a +dminUser.asp"
Thanks in advance

Replies are listed 'Best First'.
Re: Finding unique vals from a inout file
by apl (Monsignor) on Jun 30, 2008 at 18:24 UTC
    If you're using *nix, use the sort -u command.
Re: Finding unique vals from a inout file
by pc88mxer (Vicar) on Jun 30, 2008 at 17:54 UTC
    What's your desired output? It seems to be working (prints just two out of the four input lines.)
Re: Finding unique vals from a inout file
by starbolin (Hermit) on Jun 30, 2008 at 18:05 UTC

    Your code slurps the whole file into the first element of @Deploy. Probably not what you wanted.

    EDIT: As jethro= points out the original code works. So the following code is no more correct than the OP.

    Here, this works:

    Troll [113] as maint ~/ %cat foobar + [DING!] #!/usr/bin/perl @Deploy = split "\n",<DATA>; chomp(@Deploy); my @tmp = @Deploy; my %saw = (); foreach my $view_name (@Deploy) { print "view name is $view_name \n"; push (@Deploy1, $view_name) unless $saw{$view_name}++; } print join("\n",@Deploy1); __DATA__ t\test1\WEB\TEST/Admin*V:/test_viewINT/test_CVOB/test_src/Admin/AdminM +enu.asp" \\test\test1\WEB\TEST/Admin*V:/test_viewINT/test_CVOB/test_src/Admin/a +dminUser.asp" \\test\test1\WEB\TEST/Admin*V:/test_viewINT/test_CVOB/test_src/Admin/A +dminMenu.asp" \\test\test1\WEB\TEST/Admin*V:/test_viewINT/test_CVOB/test_src/Admin/a +dminUser.asp"
    Outputs two elements as I think you wanted.


    s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}
      No, it doesn't:
      #!/usr/bin/perl -w @Deploy = <>; print scalar(@Deploy);
      shows

      > ./t7.pl < t7.pl 4

        Sometimes, in spite of careful testing, one screws up. As I did. You are correct jethro.


        s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}