in reply to Deleting Duplicates in an array

I'm trying to find out what you actually want to do with in your code.
open (OWO, "+>$owo") or die $!;
That opens your file for read/write, and then truncates it to be empty.
@ary = <OWO>;
The file is empty, so this makes @ary empty.
%hsh;
This should give you a warning, using a hash in void context. You do help yourself and use -w don't you?
undef @hsh {@ary};
Not quite sure what this is supposed to do. @ary is empty. So, you are undefining nothing at all. But, even if there was something to undefine, all it undefines is values, while the rest of the code uses keys. Hence, it seems to be pointless in stereo.
@list = keys %hsh;
I've a hard time figuring out the use of this statement. It only makes sense if %hsh was populated from code you didn't show.

I would write the code somewhat like this (untested, may contain errors):

open my $fh => "+< $owo" or die "Failed to open $owe: $!\n"; my %seen; my @unique = grep {!$seen {$_} ++} <$fh>; seek $fh, 0, 0 or die "Failed to seek $owe: $!\n"; print $fh @uniqe; truncate $fh => tell $fh or die "Failed to truncate $owe: $!\n"; close $fh;
But it's shorter to write:
system "sort -u $owe > $owe.tmp; mv $owe.tmp $owe";
But that of course requires Unix, or Windows with a decent developers kit installed.

-- Abigail

Replies are listed 'Best First'.
Re: Re: Deleting Duplicates in an array
by Anonymous Monk on Jun 09, 2001 at 01:00 UTC
    Not quite sure what this is supposed to do. @ary is empty. So, you are undefining nothing at all. But, even if there was something to undefine, all it undefines is values, while the rest of the code uses keys. Hence, it seems to be pointless in stereo.
    No it' not pointless in stereo. undef undefes values, correct. But undef *defines* the *keys* of the values.
           all
      it undefines is values
    
    For a moment you had it there, to bad you didn't read your post.