[mplspm]: In a sorted list [better]
Tim Burlowski
tim.burlowski at veritas.com
Fri Mar 22 11:56:03 CST 2002
Right, I guess I was sticking with my original flow, instead of making
the solution fit the problem. I give up my brain is too foogy today.
tim
Previously Jim Anderson(jim at acadcam.com) wrote:
> On Fri, Mar 22, 2002 at 11:40:45AM -0600, Tim Burlowski wrote:
> > OK, well I missed the requirements again, as you don't want a count only
> > yes or no. Doooh. I am a double dumbass today. How about this?
> >
> >
> > #!/usr/bin/perl
> > my @list=(1,2,3,4,1,2,3,4,5,6,"string","a","string");
> > my %count = ();
> > my $i = 0;
> > $count{$_}++ for (@list);
> > my $bool = "no";
> > CHECK: foreach (keys %count) {
> > $i++;
> > if (/string/){
> > $bool = "yes";
> > last CHECK;
> > }
> > }
> > print "$bool, string found in list, $i iterations";
>
> So what's the point of spending all that time building a hash, when the
> array was already sorted???
>
> > > > Previously Josh Aas(josha at mac.com) wrote:
> > > >
> > > > > Hey MPM,
> > > > > If I have an alphabetically sorted array of strings (containing up to 2
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> > > > > million strings), and I want to find out if any strings in that array equal
>
> And with 2 million strings, building a hash is a non-trivial amount of
> time.
>
> And instead of that great big foreach loop, why not just use
>
> print "Found it\n" if defined($count{"string"});
>
> --
> Jim Anderson (612) 782-0456 jim at acadcam.com
> Anderson CAD/CAM, Inc Lucifer designed MS-DOS to try
> 3800 Apache Lane NE men's souls.
> St Anthony, MN 55421 Then he had a better idea...
>
>
> --------------------------------------------------
> Minneapolis Perl Mongers mailing list
>
> To unsubscribe, send mail to majordomo at pm.org
> with "unsubscribe mpls" in the body of the message.
--
tim burlowski
========================================
Weather conditions for Roseville, MN.
Condition are Fair, temperature is 14 degrees
with winds From the West Northwest at 14. Visibility is Unlimited.
Dewpoint 0, barometer reads 30.33 humidity at 46%.
--------------------------------------------------
Minneapolis Perl Mongers mailing list
To unsubscribe, send mail to majordomo at pm.org
with "unsubscribe mpls" in the body of the message.
More information about the Mpls-pm
mailing list