15:30 < hex> golf suggestions plz: $foo = 1 if ($bar ne 'foonly' || $baz ne 'foonly' || $honk ne 'foonly');
...
15:36 < claes> hex: working on job security?
15:37 < hex> naw, just avoiding a pile of ||s.
15:37 < claes> ah
15:37 < hex> I went for my $foo = 0; foreach ($bar, $baz, $honk) { $foo = 1 if $_ ne 'foonly'; }
15:37 < claes> hex: use Perl6::Junction
15:37 < hex> claes::D
15:38 < mauke> (grep $_ eq 'foonly', $bar, $baz, $honk) == 3 or $foo = 1;
15:38 < avar> my $foo; sub { $_ ne "foonly" && $foo = 1 for @_; 0 }->(@vars);
15:40 < kane[work]> we *so* need an 'in' statement
15:40 < mauke> "$foo $bar $baz" eq "foonly" x 3 or $foo = 1;
15:40 < kane[work]> $foo++ if 'foonly' in ($foo,$bar,$baz);
15:41 < avar> kane[work]: it's in the next release of perl
15:41 < kane[work]> of course it is
15:41 < kane[work]> everything is in perl6:)
15:41 < clintp> And a pony.
15:41 < avar> if ("foonly" ~~ @vars) { $foo = 1 }
15:41 < avar> I mean 5.10
15:41 < kane[work]> ah
15:41 < kane[work]> perl5++
15:41 < clintp> perl5++
15:41 < kane[work]> perl5++ # exists
15:43 < mauke> "@{ +{foonly => 1} }{$foo, $bar, $baz}" eq "1 1 1" or $foo = 1;
TIMTOWTDI: It's a lifestyle choice.
Apparently ~~ is the smart match operator. (Thanks to mauke for bringing it to my attention, and to clintp for the link.) I'm looking forward to 5.10....
Postscript:
17:08 < broquaint> To add to hex's golf conversation because I'm too lazy to post to use.perl: my $foo = 'foonly' !~
/^(?:$bar|$baz|$honk)$/;
More (better?) ways to do it (Score:1)
Is that really what you mean? With it, the value of
$foodepends only on$honk; the values of$barand$bazdon’t come into play at all, even though you test these variables.Also,
I think that could be just
$foo = "foonly" ~~ @vars;.But the solution I’d use is
$foo = 1 if grep $_ ne 'foonly', $bar, $baz, $honk;I don’t consider tha
Re: (Score:1)
Are you sure?
That produces "1" for me, as I expected.
The "if grep" isn't an idiom I'd previously heard. I'll bear it in mind in future.
Re: (Score:1)
Err, d’oh. Somehow I read the code as if you were resetting the variable on each iteration, which is clearly not the case. My bad.