Lingua::Pangram

Russell Matbouli russell at futureless.org
Tue Jan 22 21:48:51 CST 2002


On Wed, Jan 23, 2002 at 03:44:45AM +0000, Andrew Wilson wrote:
> You didn;t specifically ask for thsi but I'll give you it any way

Oh, cheers! Feedback is always appreciated!

> You don't need the variable $ret here it serves no purpose.  Also

As you can tell, I get a basic algorithm in my head then code it. That's
why my code looks like that... (wasteful use of variables, predeclaring
variables when I should just go ahead and do whatever, over-verbosity
and tautology even, occasionally...)

> there is no need to construct the letters and then iterate over them
> as seperate steps.  In fact perl is now optimised so that if you for
> over the 'a' .. 'z' it doesn't construct the entire list at once.

*nodding* I didn't know that... It makes sense. It's what I said above I
guess...

> If not is also unless.

A minute's thought would have told me this :)

> sub pangram {
>     my $self = shift;
>     my $string = shift;
> 
>     for ('a'..'z') {
>         return 0 unless $string =~ /$_/;
>     }
> 
>     return 1;
> }#pangram

Much nicer. Easier to read, no extra variables either.

> Schwern thinks you shouldn't explictly test for 1 and 0.  Also that
> you shouldn't document it to return those unless yuo specifically want
> them as integers.  Much better to say it returns true or false.

Okay. In my head, 0 and 1 are logically equivalent to true and false.

> Also you could probably make it more eficient by getting a list of the
> frequencys of usage of letters in english and making your list like
> qw(z q x ... etc. ) this will test the letters most likely not to be
> there first and return immediately if they aren't

Interesting idea. I'll do that when I get tuits :)

Thanks again!
-- 
Russell Matbouli       |
russell at futureless.org |     Whose turn is it to mount the scratch monkey?
PGP KeyID: 0x3CA84CF4  |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://mail.pm.org/archives/belfast-pm/attachments/20020123/d516e197/attachment.bin


More information about the Belfast-pm mailing list