[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] words words words



>>>>> "BC" == Bernie Cosell <bernie@fantasyfarm.com> writes:
> On 19 May 2000, at 9:17, tayers@bridge.com wrote:
> No epiphanies here, but this one is a lot faster than your fastest and
> not much longer than your shortest.
> 
>   #!perl -n
> 
>   BEGIN {
>     open T, "threes";
>     chop(@t=<T>);
>     @t{@t} = (1) x @t;
>   }
>   grep {!$t{$_}} /(...)/g or print;

BC> Dumb question [as I try to puzzle out how/if this works].  Is this a 
BC> typo:

>         @t{@t} = (1) x @t;
BC>       ^
BC>        '%' here, perhaps??

It's not a typo. It's a hash slice. The above line may be slightly
obfuscated because I have a hash and a list with the same name.

[ BTW my code is not insightful or novel but it is tested and produces
  the same results as Steven's first example. It produces the same
  results as Steven's second example if you don't consider case. (His
  2nd program lowercases all the words.) ]

Uri Guttman has a nice tutorial at
  http://www.sysarch.com/perl/tutorials/hash_slices.txt

BTW, the (1) x @t is unnecessary. I had started with

   #!perl -n
 
   BEGIN {
     open T, "threes";
     chop(@t=<T>);
     @t{@t}=0;
   }
   grep {!exists $t{$_}} /(...)/g or print;

which results in the first key of %t having a value of 0 and the rest
of the keys having a value of undef. But this code has more
characters, so in the spirit of shrinking code I used the hoggish
replication.

Hope you have a very nice day, :-)
Tim Ayers (tayers@bridge.com)
(and hoping the perky hackers will post some cool solutions)


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe