[Israel.pm] Golf

Levenglick Dov-RM07994 DovL at freescale.com
Wed Nov 2 10:05:06 PST 2005


my $Done = (&what(0) or "etwas");
 
Best Regards,
Dov Levenglick
DSP SoC System and Applications Engineer,
Network and Computing Systems Group
Freescale Semiconductor Israel
Tel. +972-9-952-2804
The information contained in this email is classified as:
[ ] General Business Information
[ ] Freescale Internal Use Only
[ ] Freescale Confidential Propriety
[x] Personal Memorandum
 


-----Original Message-----
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf Of Madani, Srikanth, VF-DE
Sent: Wednesday, November 02, 2005 7:36 PM
To: Perl in Israel
Subject: [Israel.pm] Golf


Hi,

I have the following code:

#!/usr/local/bin/perl -w
use strict;
sub what($);

my $Done;
$Done = what(0);
if (!defined($Done)) {
	$Done = "etwas";
}

sub what($) {
        return 1 if ($_[0]);
        return undef;
}

I wonder if it's possible to reduce the five lines of code in the middle
to a single (elegant) line?

I tried:

my $Done = defined(what(0)) ? what(0) : "etwas";
# works fine but involves an extra (unnecessary and possible harmful)
call to what()


The following doesn't compile:
my $Done = what(0) || $Done = "etwas";

Neither does this:
$Done = what(0) || my $Done = "etwas";


Of course, I can go to two lines with the straightforward:

my $Done = what(0);
$Done = "etwas" if (!defined($Done));
# Is this the most concise form?

Cheers,
Srikanth Madani

bash#> PATH=violence! /usr/bin/which sense

_______________________________________________
Perl mailing list
Perl at perl.org.il
http://perl.org.il/mailman/listinfo/perl



More information about the Perl mailing list