MACSCRPT Archives

November 2006

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Nobumi Iyanaga <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Mon, 20 Nov 2006 09:45:54 +0900
Content-Type:
text/plain
Parts/Attachments:
text/plain (42 lines)
Hello,

I didn't follow very well this thread, so I may be going to say  
something silly, but...

On Nov 20, 2006, at 2:34 AM, Paul Berkowitz wrote:

> Thanks, has. This is very helpful. And in this particular case I am
> searching through unique items, ASCII only (a list of GUIDs, in  
> fact), so no
> extra manipulations are needed.

If this is the case, perhaps the following perl script may be of some  
interest:

#!/usr/bin/perl

use strict;
use warnings;

my $a = "a, i, u, e, o";
my @a = split (/, */, $a);
my %a;
my $i = 1;
map {$a{$_} = $i; $i++} @a;
print &return_indice ("o");

sub return_indice {
	my $word = shift;
	exists $a{$word}? return $a{$word}: return 0;
}

The basic idea is that finding a 'key' value in a hash is very fast;  
so you would convert your list into a hash.  And 'map' is *perhaps*  
faster than the simple loop.

Best regards,

Nobumi Iyanaga
Tokyo,
Japan

ATOM RSS1 RSS2