My first guess:

$ perl -wle 'a+$#'
Unquoted string "a" may clash with future reserved word at -e line 1.
Use of $# is deprecated at -e line 1.
Useless use of addition (+) in void context at -e line 1.
Use of uninitialized value in addition (+) at -e line 1.
Argument "a" isn't numeric in addition (+) at -e line 1.

4 bytes, 5 warnings = 1.25 warnings / bytes

but after looking at some other solutions I thought of:

$ perl -we '$#%a'

4 bytes, 8 warnings = 2 warnings / bytes



Alistair McGlinchy wrote:

> Golfers,
>
> This list has been a tad quiet for a while so I thought I'd throw in a golfy puzzle.
>
> For some reason the keys on my keyboard temporarily rearranged themselves today and 
> a quick one-liner I was writing didn't do what I expected; in fact it did nothing at 
> all. So I added a -w flag and I got 4 separate warnings. I thought, 4 warnings ain't 
> good enough, I wanted more!
>
> In a few minutes I had a 9 byte one liner that produced 7 distinct warnings when run 
> with -w but did nothing without -w. That's 0.77 warnings per byte of code, not bad 
> but I'm sure there's more to be found.  Sure a simple perl -we 'a' gives two 
> warnings for one byte, but that seams a little too trivial.
>
> Puzzle: Write a one-liner longer than (say) 3 bytes that can improve on 0.77 
> distinct warnings per byte of code. The program should be -c valid, output nothing 
> without -w and sound the alarm as much as possible with -w.
>
> For those who like sand-traps, I suggest you shouldn't count multiple messages that 
> give the same warning for different quoted strings. For example  perl -we "a,b" 
> gives four warnings (1.3/byte) but only scores two distinct ones (0.66/byte). Nor 
> can you count the same warning on multiple lines of input.  The following will 
> hopefully give a true distinct warnings score.
>         perl -we 'yourcode'  2>&1 | perl -ne 's/\042.*\042//;s/at 
> -e.*$//;$x{$_}++;END{print 0+keys%x}'
>
> Cheers,
>
> Alistair
>
> PS please excuse the \042 in the regex I was chopping between Cygwin and cmd.exe and 
> " in cmd is a complete #£&^%$^!
> __SPOILER__GAP__
>
> __
>
> D:\>perl -ce "%$A==$@,z"
> -e syntax OK
>
> D:\>perl -e "%$A==$@,z"
>
> D:\>perl -we "%$A==$@,z"
> Unquoted string "z" may clash with future reserved word at -e line 1.
> Useless use of numeric eq (==) in void context at -e line 1.
> Useless use of a constant in void context at -e line 1.
> Name "main::A" used only once: possible typo at -e line 1.
> Use of uninitialized value in hash dereference at -e line 1.
> Argument "" isn't numeric in numeric eq (==) at -e line 1.
> Use of uninitialized value in numeric eq (==) at -e line 1.
>
> D:\>
>
> -----------------------------------------------------------------------
>
> Registered Office:
> Marks and Spencer plc
> Waterside House
> 35 North Wharf Road
> London
> W2 1NW
>
> Registered No. 214436 in England and Wales.
>
> Telephone (020) 7935 4422
> Facsimile (020) 7487 2670
>
> www.marksandspencer.com
>
> 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.

Reply via email to