Stuart White wrote:
> 
> I'm reading in lines of text, and extracting the
> relevant parts of it.  These relevant parts are then
> being pushed onto an array.  My trouble is that these
> parts are a maximum of 24 unique names.  However, when
> pushed onto the array, there is no mechanism for
> comparison where the repeated names are skipped.  I'm
> not sure how to do it.  Here's the code I have:
> 
> while (<STATS>)
> {
>  if ($_ =~ /\[($team)\] ($player)/)
>  {
>   if ($1 eq "SAN")
>         {
>          push (@SAN, $2);
> #unless ($2 eq $SAN[i]) #I need a foreach loop here
> #that will give the unless a $SAN[i] to compare
> #against the $2, I'm just not sure how to write it.
>         }
> 
>         elsif ($1 eq "PHX")
>         {
>          push (@PHX, $2);
>         }
> 
>         print "$1\t";
>   print "$2\n";
> }
> }
> foreach (@SAN)
> {
>  print "Spur roster: $_\n";
> }
> 
> In the end, I want @SAN to have all the unique names
> within the file.  Any ideas?

If you want the teams and players to be unique you should probably use a
hash of hashes (HoH):

my %stats;
while ( <STATS> ) {
    my ( $t, $p ) = /\[($team)\] ($player)/ or next;
    $stats{ $t }{ $p } = ();

    print "$t\t$p\n";
    }

for my $t ( keys %stats ) {
    print "$t roster: @{[ keys %{ $stats{ $t } } ]}\n";
    }



John
-- 
use Perl;
program
fulfillment

-- 
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