[26707] in Perl-Users-Digest
Perl-Users Digest, Issue: 8806 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 28 18:05:33 2005
Date: Wed, 28 Dec 2005 15:05:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 28 Dec 2005 Volume: 10 Number: 8806
Today's topics:
Re: "local @_ = @_;" for "pass-by-value"? (Anno Siegel)
Re: "local @_ = @_;" for "pass-by-value"? <issakov@t-online.de>
Re: "local @_ = @_;" for "pass-by-value"? (Anno Siegel)
Re: "local @_ = @_;" for "pass-by-value"? <abigail@abigail.nl>
Re: "local @_ = @_;" for "pass-by-value"? <abigail@abigail.nl>
Re: perl, v5.8.7 Windows 2003 PPM 3.3 <1usa@llenroc.ude.invalid>
Re: perl, v5.8.7 Windows 2003 PPM 3.3 <sisyphus1@nomail.afraid.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 28 Dec 2005 19:10:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: "local @_ = @_;" for "pass-by-value"?
Message-Id: <dounui$4rc$1@mamenchi.zrz.TU-Berlin.DE>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> Abigail wrote:
> > Mihail wrote:
> > @@ again about sub{} behavior and "pass-by-call"/"pass-by-value".
> > @@ Is it clean and recommended to use local @_ ?
> > @@
> > @@ sub {
> > @@ local @_ = @_;
> > @@ ...
> > @@ }
> > @@
> > @@ I do not like the way of fantasy arrays:
> > @@
> > @@ sub {
> > @@ my @pass_by_value_workaround = @_;
> > @@ ...
> > @@ }
> > @@
> > @@ It is ugly. But i still don't see clear advice how to do
> > @@ "call-by-value"? And "local" things seems to change from
> > @@ version to version.
> >
> > I would use
> >
> > my @arg = @_;
> >
> > myself, but if you like 'local @_', I don't have any problems with it.
> > Not that me having problems with it is important - it's your code, if
> > you are comfortable with it, use it.
>
> To me, doing so (or doing '@_ = @_;', which serves the same purpuse) is
> obfuscation.
It is a line of code that needs a comment, either way. In my world that
counts against using it.
> When I see a line such as
>
> $_[0] *= 8;
>
> I'm automatically assuming that the passed-in variable gets changed. If
> somebody else but the OP would later read or maintain the code,
> explicitly assigning to @_ might cause confusion.
Well, since the purpose of the action is emulating call-by-value, that
kind of code will probably not happen. I think the purpose is to protect
against hidden changes to arguments, as in
for my $thing ( @_ ) {
# ...
$thing *= 8;
# ...
}
where the programmer doesn't intend the change.
Like you, I prefer the standard method of using named lexical arguments,
even for a single array argument. Then *only* use @_ directly when you
need to, for assignment or other purposes. It doesn't make argument
changes impossible, but they will stand out, which is usually good enough.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Wed, 28 Dec 2005 20:31:53 +0100
From: Mihail <issakov@t-online.de>
Subject: Re: "local @_ = @_;" for "pass-by-value"?
Message-Id: <doup79$3hq$02$1@news.t-online.com>
>>>I would use
>>>
>>> my @arg = @_;
>>>
>>>myself, but if you like 'local @_', I don't have any problems with it.
>>>Not that me having problems with it is important - it's your code, if
>>>you are comfortable with it, use it.
>>
>
> Like you, I prefer the standard method of using named lexical arguments,
> even for a single array argument. Then *only* use @_ directly when you
> need to, for assignment or other purposes. It doesn't make argument
> changes impossible, but they will stand out, which is usually good enough.
Yes, but the way it ("pass-by-value") is done is very different.
"A "local" just gives temporary values to global (meaning
package) variables. It does not create a local variable. This is
known as dynamic scoping. Lexical scoping is done with "my", which
works more like C's auto declarations."
What is faster?
Mihail
------------------------------
Date: 28 Dec 2005 20:03:30 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: "local @_ = @_;" for "pass-by-value"?
Message-Id: <dour2i$6gp$1@mamenchi.zrz.TU-Berlin.DE>
Mihail <issakov@t-online.de> wrote in comp.lang.perl.misc:
> >>>I would use
> >>>
> >>> my @arg = @_;
> >>>
> >>>myself, but if you like 'local @_', I don't have any problems with it.
> >>>Not that me having problems with it is important - it's your code, if
> >>>you are comfortable with it, use it.
> >>
>
> >
> > Like you, I prefer the standard method of using named lexical arguments,
> > even for a single array argument. Then *only* use @_ directly when you
> > need to, for assignment or other purposes. It doesn't make argument
> > changes impossible, but they will stand out, which is usually good enough.
>
>
> Yes, but the way it ("pass-by-value") is done is very different.
Sure, but the actual behavior is very similar (though not identical).
> "A "local" just gives temporary values to global (meaning
> package) variables. It does not create a local variable. This is
> known as dynamic scoping. Lexical scoping is done with "my", which
> works more like C's auto declarations."
>
> What is faster?
Faster??? If you have to worry about the speed of parameter passing,
Perl is not your language, at least not for that part of the program.
I'd expect lexical varable(s) to be slightly faster, but that's beside the
point. The point is readability, and named lexical parameters enhance
readability while "@_ = @_" (with or without "local") obscures it.
However, as Abigail noted, it's your code, and if you really want
physical protection of the arguments, go with "@_ = @_". It works.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: 28 Dec 2005 22:37:25 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: "local @_ = @_;" for "pass-by-value"?
Message-Id: <slrndr64t5.kn.abigail@alexandra.abigail.nl>
Mihail (issakov@t-online.de) wrote on MMMMDII September MCMXCIII in
<URL:news:doup79$3hq$02$1@news.t-online.com>:
<> >>>I would use
<> >>>
<> >>> my @arg = @_;
<> >>>
<> >>>myself, but if you like 'local @_', I don't have any problems with it.
<> >>>Not that me having problems with it is important - it's your code, if
<> >>>you are comfortable with it, use it.
<> >>
<>
<> >
<> > Like you, I prefer the standard method of using named lexical arguments,
<> > even for a single array argument. Then *only* use @_ directly when you
<> > need to, for assignment or other purposes. It doesn't make argument
<> > changes impossible, but they will stand out, which is usually good enough.
<>
<>
<> Yes, but the way it ("pass-by-value") is done is very different.
<>
<> "A "local" just gives temporary values to global (meaning
<> package) variables. It does not create a local variable. This is
<> known as dynamic scoping. Lexical scoping is done with "my", which
<> works more like C's auto declarations."
<>
<> What is faster?
I don't know, and I don't care. The difference between them will be
small, and totally dwarved by the overhead of calling a subroutine,
and the actual copying itself.
If such small speed differences matter to you, you shouldn't copy @_
in the first place.
Abigail
--
perl -we 'eval {die ["Just another Perl Hacker\n"]}; print ${${@}}[$#{@{${@}}}]'
------------------------------
Date: 28 Dec 2005 22:47:09 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: "local @_ = @_;" for "pass-by-value"?
Message-Id: <slrndr65fd.kn.abigail@alexandra.abigail.nl>
Gunnar Hjalmarsson (noreply@gunnar.cc) wrote on MMMMDII September
MCMXCIII in <URL:news:41g1kkF1b5bt8U1@individual.net>:
}} Abigail wrote:
}} >
}} > I would use
}} >
}} > my @arg = @_;
}} >
}} > myself, but if you like 'local @_', I don't have any problems with it.
}} > Not that me having problems with it is important - it's your code, if
}} > you are comfortable with it, use it.
}}
}} To me, doing so (or doing '@_ = @_;', which serves the same purpuse) is
}} obfuscation.
To me, obfuscation is something that looks to do something different than
it does - or when you use a roundabout way to archieve something.
IMO, '@_ = @_;' is neither. It's a terse way to archieve something, and
it doesn't pretend to do something else.
I could understand a newbie programmer labelling it as "obfuscated", but
I doubt you'd consider yourself a newbie.
}} When I see a line such as
}}
}} $_[0] *= 8;
}}
}} I'm automatically assuming that the passed-in variable gets changed.
That raises a 'red flag' with me. Not about the code, but about the
programmer. Never 'automatically assume'. A lot of programming bugs
are made that way.
Abigail
--
#!/opt/perl/bin/perl -- # No trailing newline after the last line!
BEGIN{$|=$SIG{__WARN__}=sub{$_=$_[0];y-_- -;print/(.)"$/;seek _,-open(_
,"+<$0"),2;truncate _,tell _;close _;exec$0}}//rekcaH_lreP_rehtona_tsuJ
------------------------------
Date: Wed, 28 Dec 2005 20:22:45 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: perl, v5.8.7 Windows 2003 PPM 3.3
Message-Id: <Xns973A9C791472Aasu1cornelledu@127.0.0.1>
John Bokma <john@castleamber.com> wrote in
news:Xns973A8B80121A8castleamber@130.133.1.4:
> "Sisyphus" <sisyphus1@nomail.afraid.org> wrote:
>
>> "John Bokma" <john@castleamber.com>
>> .
>> .
>>>
>>> > A better
>>> > alternative is (imho) to install dmake and the MinGW compiler -
>>> > both of which are freely available,
>>>
>>> as is nmake, and Microsoft's C/C++ compiler...
>>
>> MSVC++6.0 (which is the recommended Microsoft compiler to use with
>> ActiveState perl) is *not* freely available. There is certainly a
>> free version of the Microsoft C/C++ compiler and you can seek out and
>> download all of the bits and pieces if you so desire
>
> IIRC just two (big) downloads.
>
>> - and use it to
>> build your own perl. But it's not a good idea to use *that* compiler
>> with ActiveState-built perl.
>
> Uhm, so Visual C++ Toolkit 2003 is a bad choice?
I am curious why that might be. I have yet to encounter a problem using
this compiler with AS Perl. On the other hand, I have not been able to
compiler Perl successfully using that (miniperl runs into trouble
something that has to do with AMD64 / XPSP2 / Symantec AV, if I
understood correctly).
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Thu, 29 Dec 2005 09:54:51 +1100
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: perl, v5.8.7 Windows 2003 PPM 3.3
Message-Id: <43b31822$0$21039$afc38c87@news.optusnet.com.au>
"John Bokma" <john@castleamber.com> wrote in message
.
.
> >
> > MSVC++6.0 (which is the recommended Microsoft compiler to use with
> > ActiveState perl) is *not* freely available. There is certainly a free
> > version of the Microsoft C/C++ compiler and you can seek out and
> > download all of the bits and pieces if you so desire
>
> IIRC just two (big) downloads.
If you want to use the free MS compiler to build perl then there's some
additional stuffing around that you have to do - see the 'Readme.win32' in
the perl source distro for details. (If that information is inaccurate,
please let me know.)
>
> > - and use it to
> > build your own perl. But it's not a good idea to use *that* compiler
> > with ActiveState-built perl.
>
> Uhm, so Visual C++ Toolkit 2003 is a bad choice?
>
No .... it's not a *bad* choice. I probably should have said that it's "not
the best idea" to use that compiler with AS perl. Chances are that you'll
use that compiler with AS perl and never be bitten. But if you try to build
Win32::SharedFileOpen on AS perl using that compiler you *will* be bitten.
(You can successfully build that module on AS perl using VC++6.0 or MinGW,
but not the free MS compiler. If you want to build it using the free MS
compiler then you'll need to be running a perl built by that compiler.)
Cheers,
Rob
------------------------------
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:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#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 V10 Issue 8806
***************************************