in reply to Re: optimization - exists should return a reference
in thread optimization - exists should return a reference

Ah, but you don't avoid the 'once-and-only-once' with the modified exists either. You'd have to write something like:
do {my $tmp = $_ -> {$client}; return $$tmp if $tmp;} for $export_def->{'..client_default_ver +sion'};

But then you have $tmp three times. And you can still leave the sigil off of $client and have strangely behaving code.

Abigail

Replies are listed 'Best First'.
Re^3: optimization - exists should return a reference
by Aristotle (Chancellor) on Jan 15, 2003 at 17:29 UTC
    do {my $tmp = $_ -> {$client}; return $$tmp if $tmp;} for $export_def->{'..client_default_version +'};
    I don't see any use of this proposed new exists (or any existance test at all for that matter) there. What are you trying to show? As BrowserUk said what I'd write then would be
    return $$_ if $_ = exists $export_def->{'..client_default_version'}{$client};
    For the purpose of demonstration, you can even avoid assignments altogether:
    { return ${ exists $export_def->{'..client_default_version'}{$client} or last } }

    Yes, if I forget the sigil on $client I'll still get strange results, but having to get it right twice still offers more room for failure, not to mention the fact that if I get the sole instance of it wrong I will get consistent rather than intermittent failure which is far easier to notice and track.

    I stand by my point, this proposition is A Good Thing in terms of promotion of good programming practices.

    Makeshifts last the longest.

Re: Re: optimization - exists should return a reference
by BrowserUk (Patriarch) on Jan 15, 2003 at 14:31 UTC

    Surely

    exists $_->{$client} and return $_->{$client} for $export_def->{'..client_default_version'};

    Would just become

    return $$_ if $_ = exists $export_def{'..client_default_version'}{$cli +ent};

    Which gives the desired once-and-once-only behaviour?


    Examine what is said, not who speaks.

    The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.