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

I didn't test Juerd's entry as I didn't have FreezeThaw installed. It seems like a complicated way of disabling warnings though?

I'm not interested in disabling warnings. I either avoid them, or don't care about them.

I used FreezeThaw to demonstrate easier syntax.

different if ( defined $x and defined $y and $x ne $y ) or not ( defined $x and defined $y );
vs
different if cmpStr($x, $y);

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.

Replies are listed 'Best First'.
Re: Re: Re: (Golf) Warningless Comparison
by BrowserUk (Patriarch) on Sep 30, 2002 at 00:47 UTC

    Firstly, sorry for mis-spelling your name.

    I also apologies for misunderstanding your intent. In the context of the thread, I looked at what FreezeThaw did, and couldn't see the difference between what it did in cmpStr($x,$y) and do{no warnings; $x eq $y). However, as I finally got FreezeThaw.pm installed on my system (actually just copied in as the install mechanism gave me inordanant troubles), I realise that it does more as my test script below shows.

    #! perl -sw use strict; use FreezeThaw qw(cmpStr freeze); sub asStr { return 'undef' if !defined $_[0]; return "''" if $_[0] eq ''; return '0' if $_[0] == 0; "$_[0]"; } my @x = (0,1,'',undef); my @y = (0,1,'',undef); print ' {$^W=0; ($x eq $y)', "\t", '!cmpStr($x,$y)', +$/; for my $x (@x) { for my $y (@y) { printf '%5s -v- %5s :', asStr($x), asStr($y); print "\t", do{local $^W=0;($x eq $y) ? 'Same' : 'Diff';}; print "\t\t",!cmpStr($x,$y) ? 'Same' : 'Diff', $/; } }

    Giving

    C:\test>test {$^W=0; ($x eq $y) !cmpStr($x,$y) 0 -v- 0 : Same Same 0 -v- 1 : Diff Diff 0 -v- '' : Diff Diff 0 -v- undef : Diff Diff 1 -v- 0 : Diff Diff 1 -v- 1 : Same Same 1 -v- '' : Diff Diff 1 -v- undef : Diff Diff '' -v- 0 : Diff Diff '' -v- 1 : Diff Diff '' -v- '' : Same Same '' -v- undef : Same Diff # Here! undef -v- 0 : Diff Diff undef -v- 1 : Diff Diff undef -v- '' : Same Diff # Here! undef -v- undef : Same Same 1:13:29.67 C:\test>

    Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!