[26708] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8807 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 28 21:05:12 2005

Date: Wed, 28 Dec 2005 18:05:03 -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: 8807

Today's topics:
    Re: "local @_ = @_;" for "pass-by-value"? <noreply@gunnar.cc>
    Re: "local @_ = @_;" for "pass-by-value"? (Anno Siegel)
    Re: "local @_ = @_;" for "pass-by-value"? <abigail@abigail.nl>
    Re: "local @_ = @_;" for "pass-by-value"? (Anno Siegel)
    Re: perl, v5.8.7 Windows 2003 PPM 3.3 <sisyphus1@nomail.afraid.org>
        Substitution not working <dreamer@cox.net>
    Re: Substitution not working <noreply@gunnar.cc>
    Re: Substitution not working <dreamer@cox.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 29 Dec 2005 00:05:38 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: "local @_ = @_;" for "pass-by-value"?
Message-Id: <41gk5uF1ellhkU1@individual.net>

Abigail wrote:
> Gunnar Hjalmarsson wrote:
> }}  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.

Newbie or not, I'm just a Perl hobbyist. :)  And, to be honest, before 
this thread, no bells would have rung if I had seen the line '@_ = @_;' 
without comments in a Perl sub.

> }}  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.

Okay, point taken. But no matter how cautious you are, the risk that you 
make mistakes is reasonably reduced if the style applied cares about 
readability.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 29 Dec 2005 01:07:26 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: "local @_ = @_;" for "pass-by-value"?
Message-Id: <dovcse$fh3$2@mamenchi.zrz.TU-Berlin.DE>

Abigail  <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMMDII September
> MCMXCIII in <URL:news:douknd$335$1@mamenchi.zrz.TU-Berlin.DE>:
> ))  
> ))  Most of the time the point is moot anyway, since most Perl subs use
> ))  named parameters
> 
> "most Perl subs"? How would you know? Have you checked all of them?

No.  Like everybody else I'm going by the unfounded assumption that
the code I happen to come across is representative for the majority
of Perl code.

> ))  
> ))      sub foo {
> ))          my( $this, $that, @array) = @_;
> 
> Those are not named parameters. Named parameters show up in the *call*
> of the function.

Okay... sloppy terminology.  What I meant was assignment of the arguments
to named (lexical) variables.

> What you have are positional parameters. Of which I
> think the overwhelming majority of Perl subs use (but I haven't checked
> them all).

Right.  And the rest use actual named parameters which also transfers
the values, usually to lexical hashes.  Direct access to @_ is rare
in published Perl code, except for one-liners.

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: 29 Dec 2005 01:07:28 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: "local @_ = @_;" for "pass-by-value"?
Message-Id: <slrndr6dmg.b7.abigail@alexandra.abigail.nl>

Gunnar Hjalmarsson (noreply@gunnar.cc) wrote on MMMMDII September
MCMXCIII in <URL:news:41gk5uF1ellhkU1@individual.net>:
-:  Abigail wrote:
-: > Gunnar Hjalmarsson wrote:
-: > }}  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.
-:  
-:  Newbie or not, I'm just a Perl hobbyist. :)  And, to be honest, before 
-:  this thread, no bells would have rung if I had seen the line '@_ = @_;' 
-:  without comments in a Perl sub.
-:  
-: > }}  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.
-:  
-:  Okay, point taken. But no matter how cautious you are, the risk that you 
-:  make mistakes is reasonably reduced if the style applied cares about 
-:  readability.


Granted. But I don't find '@_ = @_;' to be unreadable. It's a simple
assignment, and written as any other assignment. Nothing obfuscated
about it - and no hidden side-effects. It *disables* some side-effects
though - the aliasing of @_ is something many programmers get bitten
by, present company not excluded.

If I see '@_ = @_;', or '$_ = $_;' the purpose is immediately clear to
me: disabling of the effects of aliasing. And while I seldomly (perhaps
never) use '@_ = @_;', I do use '$_ = $_;', typically inside a map or a 
for statement.


Abigail
-- 
perl -le 's[$,][join$,,(split$,,($!=85))[(q[0006143730380126152532042307].
          q[41342211132019313505])=~m[..]g]]e and y[yIbp][HJkP] and print'


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

Date: 29 Dec 2005 01:24:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: "local @_ = @_;" for "pass-by-value"?
Message-Id: <dovds1$gvn$1@mamenchi.zrz.TU-Berlin.DE>

Abigail  <abigail@abigail.nl> wrote in comp.lang.perl.misc:

[...]

> If I see '@_ = @_;', or '$_ = $_;' the purpose is immediately clear to
> me: disabling of the effects of aliasing. And while I seldomly (perhaps
> never) use '@_ = @_;', I do use '$_ = $_;', typically inside a map or a 
> for statement.

I find that occasionally "$_ = $_" gets optimized away in the wrong place.
This bit of code tries to extend a bit vector $vec to at least 10 bytes
without changing its content if it is already that long:

    $_ = $_ for vec( $vec, 79, 1);

It does nothing.  Changing the assignment to "$_ = $_ + 0" works as
intended.  Arguably a bug, but I can't be bothered to report it.

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: Thu, 29 Dec 2005 10:31:12 +1100
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: perl, v5.8.7 Windows 2003 PPM 3.3
Message-Id: <43b320a6$0$9291$afc38c87@news.optusnet.com.au>


"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message
 .
 .
> >
> > Uhm, so Visual C++ Toolkit 2003 is a bad choice?
>
> I am curious why that might be.

I think "bad choice" is a little strong.

> I have yet to encounter a problem using
> this compiler with AS Perl.

Only example I know of is Win32::SharedFileOpen - but there may be other
cases, too. Here's a brief explanation from Steve Hay:

" The problems occur whenever CRT resources such as filehandles get passed
between the different CRT's.  For example, suppose you have an XS module
that uses a CRT function to get a filehandle and then the XS passes that
filehandle to some PerlIO function.  If you build the XS with VC 7 then you
get the filehandle from msvcr71.dll, but if Perl was built with VC 6 then
you're passing that filehandle to msvcrt.dll.  That definitely doesn't work.
"

(No problem with MinGW because it uses the msvcrt.dll runtime.)

> 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).
>

Did you follow the directions given in the perl source's 'Readme.win32' ?
I've not tried to build perl using the free MS compiler ... so I don't know
how good those instructions are. I expect they're excellent instructions -
as you say, the problem might well be something else.

Cheers,
Rob




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

Date: Wed, 28 Dec 2005 15:25:08 -0800
From: Fred Hare <dreamer@cox.net>
Subject: Substitution not working
Message-Id: <Z_ydnXNdJvpKgy7eRVny1g@giganews.com>

Hello there,

I want to remove <br> between the <pre> and </pre> tags in HTML files.
But the following script just hangs w/o error.
I tried s/// with /e, with /ee, with /g, etc. but nothing worked.

-- Fred

use strict;
use warnings ;

my ($string, $s_string ) ;

my $clean = do {local $/;<DATA>};

while ( $clean =~ m/(<pre>.+?<br>.+?<\/pre>)/s) {
    $s_string = $string = $1 ;
    $s_string =~ s/<br>//g ;
    $clean =~ s/$string/$s_string/ee ;     #does not work
}
    print $clean, "\n" ;
    exit ;

=cut

# This is used for testing, to show where the first script hangs:

my ($string, $s_string ) ;

my $clean = do {local $/;<DATA>};

while ( $clean =~ m/(<pre>.+?<br>.+?<\/pre>)/s) {
    $s_string = $string = $1 ;
    $s_string =~ s/<br>//g ;
    $clean =~ s/$string/$s_string/eg ;     #does not work
    print "\n", $s_string, "\n" ;
    exit ;
}

=cut

__DATA__

<p>sample text<br>for replacing br within preformatted text</p>
    <pre>
#!/usr/local/bin/perl<br>
use Tk;<br>
my $mw = new MainWindow;<br>
my $but = $mw -&gt; Button(-text =&gt; "Push Me", <br>
               -command =&gt;\&amp;push_button);<br>
$but -&gt; pack();<br>

MainLoop;<br>

sub push_button {<br>
     ... whatever ...<br>
}<br>
</pre>

    <p>
    An entry is a widget that displays a one-line text string and <br>
    allows the user to input and edit text in it. <br>
    </p>


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

Date: Thu, 29 Dec 2005 00:43:15 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Substitution not working
Message-Id: <41gmcgF1eftmtU1@individual.net>

Fred Hare wrote:
> I want to remove <br> between the <pre> and </pre> tags in HTML files.
> But the following script just hangs w/o error.
> I tried s/// with /e, with /ee, with /g, etc. but nothing worked.
> 
> use strict;
> use warnings ;
> 
> my ($string, $s_string ) ;
> 
> my $clean = do {local $/;<DATA>};
> 
> while ( $clean =~ m/(<pre>.+?<br>.+?<\/pre>)/s) {

You need the /g modifier there. (That's why the script "hangs".)

>    $s_string = $string = $1 ;
>    $s_string =~ s/<br>//g ;
>    $clean =~ s/$string/$s_string/ee ;     #does not work

Neither /e nor /ee is what you want. But $string may include characters 
that are special in regular expressions, so you may want to try:

     $clean =~ s/\Q$string/$s_string/;
----------------^^

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Wed, 28 Dec 2005 16:02:30 -0800
From: Fred Hare <dreamer@cox.net>
Subject: Re: Substitution not working
Message-Id: <7_6dnRyML-kFui7enZ2dnUVZ8qGdnZ2d@giganews.com>

Gunnar Hjalmarsson wrote:
> Fred Hare wrote:
> 
[...]
>>    $s_string = $string = $1 ;
>>    $s_string =~ s/<br>//g ;
>>    $clean =~ s/$string/$s_string/ee ;     #does not work
> 
> 
> Neither /e nor /ee is what you want. But $string may include characters 
> that are special in regular expressions, so you may want to try:
> 
>     $clean =~ s/\Q$string/$s_string/;
> ----------------^^
> 
Yes- that did it. Works fine now. Thank you Gunnar,

-- Fred


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

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 8807
***************************************


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