develooper Front page | perl.fwp | Postings from July 2003

RE: Fun - Each character at most once

July 17, 2003 14:12
RE: Fun - Each character at most once
Message ID:
> What is the most "interesting" program that is restricted to 
> use each ASCII character at most once?

The definition I chose was to check if a program (from @ARGV) contains
duplicate chars and  printing a duplicate char iff it has one. This had a
sort of "quine"y feel to it and hence could be "interesting"(tm).
Unfortunately I was stumped, the best I can do is check the first line of
the file from @ARGV. 

print <>=~m{(.)[^$/]*\1}

This is not what I'd hoped for when I started, but "print" kills so many
other useful tools, while, for, grep, map, until, if, unless, or, and.  All
the /[a-z]+/ flow-control-like functions remaining to you are "do" and
"eval".  Also it's far too easy to use up the 4 legal parens (), {} [] and
<>.  The only other printing method I can easily see is via a "!#perl -p"
line which is illegal (I presume).

Can anyone improve the above so that it checks the whole of <>, not just one
line? Bonus points for an explicit multi-character message rather than undef
on failure. 



Registered Office:
Marks & Spencer p.l.c
Michael House, Baker Street,
London, W1U 8EP
Registered No. 214436 in England and Wales.

Telephone (020) 7935 4422 
Facsimile (020) 7487 2670

Please note that electronic mail may be monitored.

This e-mail is confidential. If you received it by mistake, please let us know and then delete it from your system; you should not copy, disclose, or distribute its contents to anyone nor act in reliance on this e-mail, as this is prohibited and may be unlawful.

The registered office of Marks and Spencer Financial Services PLC, Marks and Spencer Unit Trust Management Limited, Marks and Spencer Life Assurance Limited and Marks and Spencer Savings and Investments Limited is Kings Meadow, Chester, CH99 9FB. These firms are authorised and regulated by the Financial Services Authority. Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About