MACSCRPT Archives

November 2006

MACSCRPT@LISTSERV.DARTMOUTH.EDU

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

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

Print Reply
Sender:
Macintosh Scripting Systems <[log in to unmask]>
Mime-version:
1.0
Date:
Mon, 20 Nov 2006 09:22:21 -0800
Reply-To:
Macintosh Scripting Systems <[log in to unmask]>
Content-type:
text/plain; charset="US-ASCII"
Subject:
From:
Paul Berkowitz <[log in to unmask]>
In-Reply-To:
Content-transfer-encoding:
7bit
Parts/Attachments:
text/plain (33 lines)
On 11/19/06 4:45 PM, "Nobumi Iyanaga" <[log in to unmask]> wrote:

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

Thanks, Nobumi. Is this convertible to a single-line perl -e Terminal script
which could be quoted and run as a 'do shell script', or must it be run from
a file?

-- 
Paul Berkowitz

ATOM RSS1 RSS2