in reply to sorting arrays...

You are not sorting the data all in your code. For sorting you require to get all the data in memory and then sort. You can do by storing in a hash. Assuming your names appear only once in your data, try following code.
my $whatever; my @sortedarray; open(SORTED, ">sorted.txt"); open(TOSORT, "tosort.txt"); my %hash; while ($whatever = <TOSORT>) { chomp $whatever; my($name,$number) = split(/\|/, $whatever); $hash{$name} = $number; } foreach my $name (sort keys %hash){ my $number = $hash{$name}; print "$name\|$number"; } close(TOSORT); close(SORTED);

artist

Replies are listed 'Best First'.
Re: Re: sorting arrays...
by iamrobj (Initiate) on Jul 12, 2003 at 22:07 UTC
    This way sorted the name and not the number?
      Sorry about my mistake in reading your question:
      Replace this:
      my %hash; while ($whatever = <TOSORT>) { chomp $whatever; my($name,$number) = split(/\|/, $whatever); $hash{$number} = $name; } foreach my $number (sort keys %hash){ my $name = $hash{$number}; print "$name\|$number"; }
      artist
        Thanks! :)