That opens your file for read/write, and then truncates it to be empty.open (OWO, "+>$owo") or die $!;
The file is empty, so this makes @ary empty.@ary = <OWO>;
This should give you a warning, using a hash in void context. You do help yourself and use -w don't you?%hsh;
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.undef @hsh {@ary};
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.@list = keys %hsh;
I would write the code somewhat like this (untested, may contain errors):
But it's shorter to write: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 that of course requires Unix, or Windows with a decent developers kit installed.system "sort -u $owe > $owe.tmp; mv $owe.tmp $owe";
-- Abigail
In reply to Re: Deleting Duplicates in an array
by Abigail
in thread Deleting Duplicates in an array
by blacksmith
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |