in reply to how to sort uniq $array[2]

I've no idea what $scalar is supposed to be; but let's assume it's the name of a file you want to sort. You could do:
use autodie ':all'; system "sort -u '$scalar' > '$scalar.sorted'"; rename "$scalar.sorted", $scalar;

Replies are listed 'Best First'.
Re^2: how to sort uniq $array[2]
by auto_w (Novice) on Jun 06, 2011 at 12:53 UTC

    well $scalar we can just disregard - i wanted to sort @array2 , that is where www.*****.com servers will be after split function

    #!/usr/bin/perl -w use strict; find_serv (); sub find_serv { @ARGV == 2 || die "usage: $0 INDEX_FILE '.com'\n";# .com---->icq.com my ( $INDEX_FILE, $com ) = @ARGV; my $list = "grep 'href=' $INDEX_FILE|" ;#- $INDEX_FILE --> wget www. +icq.com open (my $HAN, "$list" ) || die "Cannot open '$INDEX_FILE' because:: +$!"; while (<$HAN>) { chomp $_; my @array = split (/\//, $_); if ($array[2] =~ /$com/ ){#matches icq.com my @sorted = $array[2]; system "sort -u '@sorted'"; #---not working }} }
      But what is $array[2]? A name of a file? In that case, take my previous answer, and replace $scalar with $array[2].

        well $array2 -is third field of a file that has been split by / @array -contains all fields when i did like you said i got error - sort:open failed no such file or directory it shouldn't be all that complex i think instead of www.google.ie www.google.ie www.google.ie to get: www.google.ie

        #!/usr/bin/perl -w use strict; find_serv (); sub find_serv { @ARGV == 2 || die "usage: $0 INDEX_FILE '.com'\n";# .com---->icq.com my ( $INDEX_FILE, $com ) = @ARGV; my $list = "grep 'href=' $INDEX_FILE|" ;#- $INDEX_FILE --> wget www. +icq.com open (my $HAN, "$list" ) || die "Cannot open '$INDEX_FILE' because:: +$!"; while (<$HAN>) { chomp $_; my @array = split (/\//, $_); if ($array[2] =~ /$com/ ){#matches icq.com my @sort = $array[2]; #my $result = `sort -u '$sorted'`; #print "$result\n"; system "sort -u '$array[2]' > '$array[2].sorted'"; rename "$array[2].sorted", $array[2]; print "$array[2]n"; }} } #END