On Wed, Oct 18, 2006 at 03:04:32PM -0400, Johnson, Reginald (GTI) wrote:

> I am trying to understand this sort and uniq code that a came across in
> the archive.

I don't see anything to do with sort in this code.

>              This works, but I thought the %uniq  would have the sort
> and uniqed values.

Yes, the keys of %uniq are the unique values.

>                    What is needed if I didn't want to print the values
> out immediatedly but put them in an array or hash?

Since they are already put in the hash, you just get rid of the print part.

> #!/usr/bin/perl
> use strict;
> use warnings;
> 
>                 my @holdArr =qw(apple pear lemon bananna apple pear);
>                 my %uniq;
>                 map{$uniq{$_}=1 and print "$_\n"  unless [EMAIL PROTECTED];

map{$uniq{$_}=1 unless [EMAIL PROTECTED];

But that's still pretty horrible code.

@[EMAIL PROTECTED] = ();

will also leave the keys of %uniq holding the unique values.

See the first section of perldoc perldata.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to