On 5/19/2004 12:30 AM, Ramprasad A Padmanabhan wrote:
On Wed, 2004-05-19 at 08:35, Randy W. Sims wrote:
On 5/18/2004 11:00 PM, Randy W. Sims wrote:
sub uniq { return keys %{{ map { $_, 1 } @_ }} }
Sorry for the nice formatting, that should have been:
sub uniq{keys%{{map{$_,[EMAIL PROTECTED]
Are u sure that works ? I just wrote out a script didnot work for me
#!/usr/bin/perl
my @arr = qw(a b c d a b e f ); print join(" " , sort @arr) . "\n" . '#' x 50 . "\n"; print join(" " , sort (uniq (@arr))) . "\n"; exit 0; sub uniq{keys%{{map{$_,[EMAIL PROTECTED] __END__
The output I got was
a a b b c d e f ################################################## a b c d a b e f
I dont think there is anything wrong with the function uniq, the function works fine ( when I print within the function ). I think the issue is with the return
use strict; use warnings;
There is ambiguity in your call to the function; perl does not know it is a function. Prefix the call with '&' or '+', and it will work. A better solution might be to use temporaries to construct your list.
Randy.
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>