[33169] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4448 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 9 14:09:15 2015

Date: Tue, 9 Jun 2015 11:09:03 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 9 Jun 2015     Volume: 11 Number: 4448

Today's topics:
        avoid explicit dereferencing for methods/ subroutines <rweikusat@mobileactivedefense.com>
    Re: avoid explicit dereferencing for methods/ subroutin <rweikusat@mobileactivedefense.com>
        more reference naming <rweikusat@mobileactivedefense.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 09 Jun 2015 17:10:27 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: avoid explicit dereferencing for methods/ subroutines
Message-Id: <87r3pkg8wc.fsf@doppelsaurus.mobileactivedefense.com>

Methods are presumably the most frequent users of explicit
dereferencing and it's actually possible to avoid that entirely without
adding 'strange, new features' to the language. A method

sub finish
{
    my $self = $_[0];
    my $what;

    $what = pop(@{$self->[SYNS]});
    $self->[OUT] .= ' '.$delims{$what}[1];
    $self->[DELIM] = '' unless @{$self->[SYNS]};

    p_alloc(indent_for($self) . 'finish_%s', $names{$what});
}

could be rewritten as

sub finish
{
    local *self = \shift;
    my $what;

    $what = pop(@{$self[SYNS]});
    $self[OUT] .= ' '.$delims{$what}[1];
    $self[DELIM] = '' unless @{$self[SYNS]};

    p_alloc(indent_for($self) . 'finish_%s', $names{$what});
}

since glob assignment can be used to name references and local to
restrict the scope of such an assignment (it'll still be visible from
subroutines called from this one but this could be considered 'a
feature' as it makes the current object instance globally available
without passing it around).


------------------------------

Date: Tue, 09 Jun 2015 17:51:58 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: avoid explicit dereferencing for methods/ subroutines
Message-Id: <87a8w8g6z5.fsf@doppelsaurus.mobileactivedefense.com>

Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
> Methods are presumably the most frequent users of explicit
> dereferencing and it's actually possible to avoid that entirely without
> adding 'strange, new features' to the language. A method
>
> sub finish
> {
>     my $self = $_[0];
>     my $what;

[...]

> sub finish
> {
>     local *self = \shift;

This is wrong since $_[0] will already be a reference (I tested the
construct with an ordinary subroutine), the \ has to be omitted.


------------------------------

Date: Tue, 09 Jun 2015 18:20:41 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: more reference naming
Message-Id: <874mmgg5na.fsf@doppelsaurus.mobileactivedefense.com>

Another example (from the same code, this time, I've tested both
variants)

sub in_dict($)
{
    my $self = $_[0];
    return @{$self->[SYNS]} && $self->[SYNS][$#{$self->[SYNS]}] == JS_DICT;
}

versus

sub in_dict($)
{
    local *_ = $_[0]->[SYNS];
    return @_ && $_[$#_] == JS_DICT;
}

Uses *_ because strict won't complain about that. I didn't even think of
expressing the first term with $_[0] instead of the temporary.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 4448
***************************************


home help back first fref pref prev next nref lref last post