> Ok I know what it does ('cause I ran it, see below) but I
> still don't fully
> understand how.
Well, it's a trick, based on the "givens" that neither array contained any
duplicates. If each item appears at most once per array, then all we need
to do is count the number of times each item a
"Stout, Joel R" wrote:
>
> Ok I know what it does ('cause I ran it, see below) but I still don't fully
> understand how. Also can you give a little insight into passing arrays to
> subroutines/functions. I can pass them alright but have problems accessing
> them. I use $_[0] but it doesn't see
i}++;
}
@result = ();
foreach $k (keys %h)
{
$h{$k}--;
push @result, $k if $h{$k};
}
return @result;
}
Prints: c #the only thing common to both lists
-Original Message-
From: Nutter, Mark [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 20, 2001 6
Paul Johnson wrote:
> But don't go relying on the ordering of the array. Hashes don't
> preserve order. If you need an ordering, impose it. eg
>
> print join "\n", sort @ary;
Should we get into a thread on 'sort' ~8^) ?
I thought I'd throw this in there (in case some of you get adventur
On Fri, Apr 20, 2001 at 09:29:04AM -0400, Nutter, Mark wrote:
>bash$ perl -e '
>> @ary = ('a', 'b', 'c', 'b', 'a');
>> %hsh = (); # empty hash
>>
>> foreach $item (@ary)
>> {
>> $hsh{$item} = 1;
>> }
>>
>> @ary = keys %hsh;
>>
>> print (join "\n", @a
> foreach $i (@a, @b) # did you know you can combine
> arrays like this?
> :)
Oops, darn line wrap, please ignore the smiley...
Here's some real basic info about hashes...may be useful to newbies...
@ary = ('a', 'b', 'c', 'b', 'a');
%hsh = (); # empty hash
foreach $item (@ary)
{
$hsh{$item} = 1;
}
@ary = keys %hsh;
What does @ary contain now?
You can think of a hash as being like an array that is indexed by st