in reply to Re: Re: (Golf) Warningless Comparison
in thread (Golf) Warningless Comparison

If you change the specs to the challenge, any thing is possible.

My version does not produce warnings under the terms of the challenge. Note:the localisation and setting of $^W=0.


Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!
  • Comment on Re: Re: Re: (Golf) Warningless Comparison

Replies are listed 'Best First'.
Re: Re: Re: Re: (Golf) Warningless Comparison
by demerphq (Chancellor) on Sep 29, 2002 at 20:24 UTC
    If you change the specs to the challenge, any thing is possible.

    Advice you should take to heart. From the OP:

      Since warnings are supposed to be avoided, use strict; use warnings;

    My version does not produce warnings under the terms the unmodifies rules of the challenge. Note:the localisation and setting of $^W=0.

    The original terms of the challenge call for it to not produce warnings when run under use warnings. Yours does. The local $^W stuff doesnt have the effect you think it does when used under use warnings; It works the way you think it does when run under only "-w" but that isnt the same thing. It also doesnt work the way you think it does when run under both "-w" and use warnings;. From perllexwarn:

      If a piece of code is under the control of the warnings pragma, both the $^W variable and the -w flag will be ignored for the scope of the lexical warning.

    Also, next time try running the code before you get so insistant it works the way you think it does....

    --- demerphq
    my friends call me, usually because I'm late....

      I am aware of the differences between -w and use warnings. I chose to use -w and $^W=0 within the localised scope of a subroutine who's sole purpose was to avoid them, which is I think, a legimite tactic given this was golf and only keystrokes count.

      The reasons why my (fully tested*) code both produced warnings and apparently failed to produce the desired output, was because you ran it in a context different from that in which it was designed to run and made no attempt to correct for that change of context in any meaningful way.

      In fact you deliberately suppressed the (correct) output for reasons I can only speculate on.

      vis.

      #! perl -w use warnings; use strict; my $foo = { aa => { O => 'zz', C => 'yy' }, # bb => { O => 'xx', C => 'xx' }, cc => { O => undef, C => 'ww' }, # dd => { O => 'vv', C => undef }, # ee => { O => undef, C => undef }, ff => { C => undef }, gg => { O => 0, C => 0 }, hh => { O => undef, C => 0 }, # }; #234567890123456789012345678901234567890123456789012345678901234567890 +1234567890123 sub f{no warnings;$a=pop;grep{!exists$a->{$_}{O}or$a->{$_}{O}ne$a->{$_ +}{C}}keys%$a} # 83! print "@{[f($foo)]}\n"; __DATA__ C:\test>201598 dd ff aa hh cc C:\test>

      Even in this form, it still complies with the original spec and comes in at 83

      *My original post contained both fully working program and its output unedited. No warnings, and the required output.


      Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!
        Wow. I cant believe you're still pursuing this. Your code didnt do what it was supposed to. You can mumble about "the context it was written in" all you like. The rules said "Since warnings are supposed to be avoided, use strict; use warnings;". And your code fails this part of the specification.

        I chose to use -w and $^W=0 within the localised scope of a subroutine who's sole purpose was to avoid them, which is I think, a legimite tactic given this was golf and only keystrokes count.

        As you said to me earlier

          If you change the rules of Formula 1 to have a mandatory water section and then enter in a D.U.K.W., you'll likely win every race.

        and
          If you change the specs to the challenge, any thing is possible.

        So you have changed the terms of the challenge to suit yourself. Very sportsmanlike. Not.

        (fully tested*)

        Fully tested under different terms than were specified for the challenge. Not fully tested under the terms of the challenge.

        because you ran it in a context different from that in which it was designed to run and made no attempt to correct for that change of context in any meaningful way.

        Im very sorry that I ran your code under the terms of the original challenge. Im very sorry I ran your code at all. (In fact I thought it was pretty neat, and tried to extend it. I now realize that I wasted my time.)

        In fact you deliberately suppressed the (correct) output for reasons I can only speculate on.

        What on earth are you talking about? Clearly you have completely lost the plot. I suppressed nothing. All I did was extend the test cases to handle a number of omitted difficult scenarios. Admittedly I didnt notice the rule that invalidated test case 'ii' but I apologised when you pointed out the rule (while lecturing me about changing the rules, something you seem to like to do yourself.) As for the warn=>die promotion I did that to automate the capturing and notification of warnings.

        Please substantiate or retract your assertion that I suppressed something.

        Even in this form, it still complies with the original spec and comes in at 83

        Well, if this means that it pasess the provided test cases, then yes finally you have done it. However I dont believe that simply passing the test cases is sufficient. I believe that the spirit of the challenge was the following

          How compact can a function be that, when given a HASH reference, returns a list of those entries which have changed. In other words, where the 'original' is not the same as 'new'. As a note, the 'new' value is always present, even if it is undef.

        Which your code DOESNT do. Consider that undef ne '' is false. However the two are clearly different. Since this is the basis of your solution it fails the challenge and its size is irrelevent.

        I have added more test cases, tracked down the annoying bug in Elusions code that causes the original hash to become corrupt (I changed F($foo) to F({%$foo}) to avoid this impacting other attempts.)

        So despite all of your blustering you have posted four solutions that fail the challenge. And in the process insulted someone who started out impressed and friendly. Nice work!

        Required: aa cc dd ff hh jj kk ll mm nn oo pp ---------------------------------------------------------------------- +-- tadman golf: aa cc dd ff hh jj kk ll mm nn oo pp main::BUK() => Use of uninitialized value in string ne at c:\temp\ +golf.pl line 25. sauoq No warns: aa cc dd hh jj kk ll mm main::sg_() => Use of uninitialized value in string eq at c:\temp\ +golf.pl line 27. Elusion golf: aa cc dd jj kk ll mm Demerphq defd: aa cc dd hh jj kk ll mm nn oo pp Demerphq exist: aa cc dd ff hh jj kk ll mm nn oo pp main::ukf() => Use of uninitialized value in string ne at c:\temp\ +golf.pl line 33. main::ukg() => Use of uninitialized value in string ne at c:\temp\ +golf.pl line 32. main::ukh() => Use of uninitialized value in string ne at c:\temp\ +golf.pl line 34. browserUk F(): aa cc dd ff hh jj kk ll mm

        ---
        demerphq
        You haven't lived until you've done 140mph in a Jaguar E type convertable!