Lingua::Pangram

Marty perl.belfast at kasei.com
Fri Jan 25 10:18:41 CST 2002


On Thu Jan 24 19:35:24 2002, Smylers wrote:
> 
>   perl -ne'@$_{/[a-z]/gi}=1;%$_>25&&print'  # 40
> 
> It relies on the hashing sticking each letter of the alphabet in a
> separate bucket but upper- and lower-case versions of the same letter in
> the same bucket.  This seems to work on 5.005_03; I haven't test it on
> anything else.

Fail my test with 5.6.1: the upper case letters don't quite work,
although the lower case behaviour is the same.

> But why does it still print the right thing at the end?  This version
> works as expected:
> 
>   perl -ne'my%k;@k{/[a-z]/gi}=1;%k>25&&print'  # 43

And that version will run under strict; your previous version won't, and
trying it should give a clue to why it works at all.

> In fact, in this:
> 
>   perl -nle'@$_{/[a-z]/gi}=1;%$_>25&&print"$_:".%$_'
> 
> it's even possible to have Perl use $_ as a string, then me use it as a
> hash ref, then print the string, and then print the hash ref!  Surely $_
> should print "HASH(0x80d43dc)" or something?

No.  You are using (evil) symbolic refererences.  That is, if $_
contains the string "this is a test", then the name of your hash
variable is effectivly %'this is a test'.

> Please can somebody explain what I'm missing here?

-Mstrict should explain it for you.

Have fun!

-- 
Marty
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 220 bytes
Desc: not available
Url : http://mail.pm.org/archives/belfast-pm/attachments/20020125/f9db8d89/attachment.bin


More information about the Belfast-pm mailing list