Subject: | |
From: | |
Reply To: | |
Date: | Mon, 20 Nov 2006 09:22:21 -0800 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
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
|
|
|