[32350] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3617 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 22 09:09:27 2012

Date: Wed, 22 Feb 2012 06:09:10 -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, 22 Feb 2012     Volume: 11 Number: 3617

Today's topics:
        [OT] addresses and interfaces (was Re: Can't connect to <m@rtij.nl.invlalid>
    Re: a question about efficiency <kiuhnm03.4t.yahoo.it>
    Re: a question about efficiency <kiuhnm03.4t.yahoo.it>
    Re: a question about efficiency (Tim McDaniel)
    Re: a question about efficiency <ben@morrow.me.uk>
    Re: a question about efficiency <ben@morrow.me.uk>
    Re: a question about efficiency (Seymour J.)
    Re: a question about efficiency <rweikusat@mssgmbh.com>
    Re: a question about efficiency (Seymour J.)
    Re: a question about efficiency (Greg Bacon)
    Re: a question about efficiency (Tim McDaniel)
    Re: a question about efficiency <m@rtij.nl.invlalid>
    Re: a question about efficiency <justin.1201@purestblue.com>
    Re: a question about efficiency <rweikusat@mssgmbh.com>
    Re: a question about efficiency <rweikusat@mssgmbh.com>
    Re: a question about efficiency (Seymour J.)
    Re: a question about efficiency (Seymour J.)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 22 Feb 2012 14:12:09 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: [OT] addresses and interfaces (was Re: Can't connect to 'localhost' in IO::Socket)
Message-Id: <966f19-bkq.ln1@news.rtij.nl>

On Wed, 22 Feb 2012 12:16:34 +0000, Ben Morrow wrote:

I agree this has little to do with the OP's question, but the concepts 
involved are important, and Wolfram was just plain wrong. It's a very 
common misunderstanding and that is why I reacted.

> Rainer was (implicitly) talking about using a specific socket binding as
> a means of filtering connections by *source* address. He is quite
> correct this isn't possible on a weak ES; it's also just as stupid and
> dangerous as any other form of filtering by IP that isn't backed up by
> some more secure form of authentication.

Actually he wasn't. What he was pointing out (which had nothing to do 
with the OPs question, I agree) is that a WES accepts connection on any 
address on any interface. Not just on the interface the address is 
configured on. 

> 
> The OP's problem was to do with a specific socket binding filtering
> connections by *destination* address. This happens on all (not-
> completely-broken) systems: even a vanilla unfirewalled Unix system
> won't accept connections destined for one address on a socket bound to a
> different address. It's often important to be careful about socket

Correct.

> bindings for this reason: for instance, a server that uses SSL or
> Kerberos that thought it was serving on address A will fail to
> authenticate connections where the client was trying to connect to
> address B.

I don't know about Kerberos, but this is not true for SSL.

> In any case, Unix systems can generally be configured as strong ESs now,
> at least as far as requirement (A) (rejecting packets coming in on the
> wrong interface) goes. Most firewall packages have some sort of
> 'antispoof' mechanism that does this.

Ah, no. You are confusing anti-spoofing with strong end systems 
requirements. One deals with source addresses, the other with destination 
addresses. If you want strong end behavior, you have to put that into 
firewall rules yourself. 

M4


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

Date: Tue, 21 Feb 2012 23:06:07 +0100
From: Kiuhnm <kiuhnm03.4t.yahoo.it>
Subject: Re: a question about efficiency
Message-Id: <4f44154e$0$1380$4fafbaef@reader2.news.tin.it>

On 2/21/2012 20:36, Tim McDaniel wrote:
> In article<4f43d60b$0$1387$4fafbaef@reader2.news.tin.it>,
> Kiuhnm<kiuhnm03.4t.yahoo.it>  wrote:
>> Of course. What strikes me is that strange "for".
>
> They're called "statement modifiers" in "man perlsyn".
>
>> Finally I can omit those hideous curly braces.
>
> If you think curly braces are "hideous", you might prefer using some
> other language instead.

How drastic!

>  Or you might like Lingua::Romana::Perligata,
> http://www.csse.monash.edu.au/~damian/papers/HTML/Perligata.html

Wow... I hate Latin (I was forced to learn it in high school) but that's 
quite original.

Kiuhnm


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

Date: Tue, 21 Feb 2012 23:14:06 +0100
From: Kiuhnm <kiuhnm03.4t.yahoo.it>
Subject: Re: a question about efficiency
Message-Id: <4f44172d$0$1379$4fafbaef@reader2.news.tin.it>

On 2/21/2012 21:06, Rainer Weikusat wrote:
> Kiuhnm<kiuhnm03.4t.yahoo.it>  writes:
>> On 2/21/2012 19:16, Rainer Weikusat wrote:
>>> ... which would server as further indication that they are not. Also,
>>> the average difference between two successive value supposedly
>>> measuring the same quantity varies between 17.2 (a) and 245.64
>>> (d). How can this be for a deterministic phenomenon which has been
>>> measured accurately?
>>>
>>>> And the results won't change if I go from 20 s. to "just" 5 s.:
>>>> Why should they?
>>>
>>> Assuming that each individual measurement is composed of an accurate
>>> part and some random error, it can be expected that the random errors
>>> will tend to cancel out when a 'sufficiently large' number of
>>> individual measurements is averaged. Which implies that longer
>>> sequence ought to yield more accurate results.
>>>
>>> But this looks suspiciciously like something people should learn when
>>> they are about 16 or so ...
>>
>> No need to be so defensive.
>
> That was just my last attempt to assume ignorance instead of malice.
> HAND.

I knew it: I shouldn't have told you about the missing "l" :(

Kiuhnm


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

Date: Tue, 21 Feb 2012 22:32:33 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: a question about efficiency
Message-Id: <ji1621$4i3$1@reader1.panix.com>

In article <4f44154e$0$1380$4fafbaef@reader2.news.tin.it>,
Kiuhnm  <kiuhnm03.4t.yahoo.it> wrote:
>On 2/21/2012 20:36, Tim McDaniel wrote:
>> In article<4f43d60b$0$1387$4fafbaef@reader2.news.tin.it>,
>> Kiuhnm<kiuhnm03.4t.yahoo.it>  wrote:
>>> Of course. What strikes me is that strange "for".
>>
>> They're called "statement modifiers" in "man perlsyn".
>>
>>> Finally I can omit those hideous curly braces.
>>
>> If you think curly braces are "hideous", you might prefer using
>> some other language instead.
>
>How drastic!

I think cashews and pecans and peanuts are great.  If you're allergic
to them, why can't I suggest you try other things?

If curly braces are going to make you grit your teeth and detest the
language whenever you deal with them, why not save yourself the pain?

I've heard good things about Ruby.  At a quick glance, it has no curly
braces for control flow, but does use them for hashes.  I don't know
how much power it has, but the one report I heard of was from a
long-time Perl expert, and he had no complaints about things he could
do in Perl but could not do in Ruby.

-- 
Tim McDaniel, tmcd@panix.com


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

Date: Tue, 21 Feb 2012 23:58:28 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: a question about efficiency
Message-Id: <4mnd19-788.ln1@anubis.morrow.me.uk>


Quoth tmcd@panix.com:
> In article <4f438e22$0$1390$4fafbaef@reader2.news.tin.it>,
> Kiuhnm  <kiuhnm03.4t.yahoo.it> wrote:
> >Hi,
> >I've just started to learn Perl. Here's my first question.
> >
> >Please look at this code:
> >--->
> >   my $len1;
> >   foreach (keys %ENV) {
> >     if (length $_ > $len1) { $len1 = length $_ }}
> ><---
> >Does Perl execute "length $_" twice or once?
> >Should I use
> >   if ((my $l = length $_) > $len1) { $len1 = $l }}
> >instead?
> 
> Some great answers have been given.  I'll just add two small points:
> 
> "Micro-optimization leads to micro-results."
> 
> For doing max and min, I personally prefer a more parallel-looking
> structure like
>     if ($len1 < length $_) {
>         $len1 = length $_;
>     }

    use List::Util qw/max/;

    my $len1 = max map length, keys %ENV;

(I predict this will also be fastest, but I can't be bothered to
benchmark. If you were counting a *really* large hash and you used
while(each) instead of for(keys) you might save a bit of time by
avoiding some memory allocation, but otherwise doing the max in C
instead of Perl is almost certain to be a win.)

If I were feeling this was unclear, or if the expressions were longer, I
might split it up into separate operations, like this:

    my $len1 = 
        max
        map length,
        keys %ENV;

Ben



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

Date: Tue, 21 Feb 2012 23:49:52 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: a question about efficiency
Message-Id: <06nd19-788.ln1@anubis.morrow.me.uk>


Quoth Kiuhnm <kiuhnm03.4t.yahoo.it>:
> On 2/21/2012 16:44, Ben Morrow wrote:
> 
> > (Technically they aren't closures in this instance, just anonymous
> > subroutines, because they don't close over any outer variables. This is
> > nearly never an important distinction.)
> 
> Well, theoretically, a closure doesn't need to "capture" outer variables 
> to be called a closure. But you already know that.

I didn't, actually :). I have no formal training in computer science,
just what I've picked up here and there. At any rate, I do know that
perl internally considers anonymous subs which do in fact close over
outer variables to be different from those which don't; in particular,
a sub {} which doesn't close over anything will return a ref to the same
sub every time, whereas one which doesn't won't. So:

    ~% perl -E'say for map { sub { 1 } } 1..2'
    CODE(0x821928)
    CODE(0x821928)
    ~% perl -E'say for map { my $x; sub { $x } } 1..2' 
    CODE(0x803aa8)
    CODE(0x8196c8)
    ~% 

(and there are a couple more Perl idioms for you :) ).

Ben



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

Date: Tue, 21 Feb 2012 16:34:04 -0500
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: a question about efficiency
Message-Id: <4f440dcc$3$fuzhry+tra$mr2ice@news.patriot.net>

In <4f43d60b$0$1387$4fafbaef@reader2.news.tin.it>, on 02/21/2012
   at 06:36 PM, Kiuhnm <kiuhnm03.4t.yahoo.it> said:

>Of course. What strikes me is that strange "for". 

See statement modifiers in perlsyn.

>"Learning Perl" won't give me too many details until my fragile mind
>is  ready to assimilate them :)

I found that it was easier to learn from "Programming Perl" than from
"Learning Perl".

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org



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

Date: Wed, 22 Feb 2012 01:04:19 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: a question about efficiency
Message-Id: <87pqd7y8z0.fsf@sapphire.mobileactivedefense.com>

Ben Morrow <ben@morrow.me.uk> writes:
> Quoth tmcd@panix.com:
>> In article <4f438e22$0$1390$4fafbaef@reader2.news.tin.it>,
>> Kiuhnm  <kiuhnm03.4t.yahoo.it> wrote:
>> >Hi,
>> >I've just started to learn Perl. Here's my first question.
>> >
>> >Please look at this code:
>> >--->
>> >   my $len1;
>> >   foreach (keys %ENV) {
>> >     if (length $_ > $len1) { $len1 = length $_ }}
>> ><---
>> >Does Perl execute "length $_" twice or once?
>> >Should I use
>> >   if ((my $l = length $_) > $len1) { $len1 = $l }}
>> >instead?
>> 
>> Some great answers have been given.  I'll just add two small points:
>> 
>> "Micro-optimization leads to micro-results."
>> 
>> For doing max and min, I personally prefer a more parallel-looking
>> structure like
>>     if ($len1 < length $_) {
>>         $len1 = length $_;
>>     }
>
>     use List::Util qw/max/;
>
>     my $len1 = max map length, keys %ENV;
>
> (I predict this will also be fastest, but I can't be bothered to
> benchmark.

It is (according to a single measurement since I can't be bothered to
spend a serious effort on disproving other peoples phantasies) in the
same league as the other two good versions. Since it again needs to
perform roughly the same operations, this is to be expected (perl
isn't that bad). Sorry but there's really no magic "code distributed
together with Perl" bonus. That's still an indication of the social
state of the author, not of his technical abilities in general, and
certainly not of his ability to work inexplainable magic. 


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

Date: Tue, 21 Feb 2012 19:59:30 -0500
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: a question about efficiency
Message-Id: <4f443df2$4$fuzhry+tra$mr2ice@news.patriot.net>

In <ji1621$4i3$1@reader1.panix.com>, on 02/21/2012
   at 10:32 PM, tmcd@panix.com (Tim McDaniel) said:

>I don't know how much power it has,

Just the core language? One of the things that makes Perl attractive
is CPAN.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org



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

Date: Tue, 21 Feb 2012 21:55:01 -0600
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: a question about efficiency
Message-Id: <-POdnUXcZo6I-tnSnZ2dnUVZ_q2dnZ2d@posted.hiwaay2>

Kiuhnm <kiuhnm03.4t.yahoo.it> wrote

: [...]
: Well, theoretically, a closure doesn't need to "capture" outer
: variables to be called a closure. But you already know that. I guess
: it depends on how a community see things.

I’m curious to see examples of this usage. Without closing over the
lexical environment, what’s left is a function pointer.

Greg
-- 
There are better ways to earn a living than to prevent other people from
making use of one's contributions to computer science.
    -- Donald Knuth


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

Date: Wed, 22 Feb 2012 06:39:25 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: a question about efficiency
Message-Id: <ji22it$79h$1@reader1.panix.com>

In article <4f443df2$4$fuzhry+tra$mr2ice@news.patriot.net>,
Shmuel (Seymour J.) Metz  <spamtrap@library.lspace.org.invalid> wrote:
>In <ji1621$4i3$1@reader1.panix.com>, on 02/21/2012
>   at 10:32 PM, tmcd@panix.com (Tim McDaniel) said:
>
>>I don't know how much power it has,
>
>Just the core language? One of the things that makes Perl attractive
>is CPAN.

Unfortunately, too often I've been stuck on servers where I am not a
sysadmin or otherwise dare not touch Perl.  I can do modules for
myself, but that doesn't help with code for others.

-- 
Tim McDaniel, tmcd@panix.com


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

Date: Wed, 22 Feb 2012 09:43:25 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: a question about efficiency
Message-Id: <deme19-j7p.ln1@news.rtij.nl>

On Tue, 21 Feb 2012 19:05:46 +0100, Kiuhnm wrote:

>> For doing max and min, I personally prefer a more parallel-looking
>> structure like
>>      if ($len1 < length $_) {
>>          $len1 = length $_;
>>      }
> 
> I still hate the two braces (6 keys on my keyboard), but that's
> undeniably much more readable.

as has been pointed out before:

$len1 < length $_ or $len1 = length $_;

or:

$len1 = length $_ if $len1 < length $_;

or with braces, but reusable and readable in use:

sub max { $_[0] < $_[1] ? $_[1] : $_[0] }

$len1 = max($len1, $length);

TIMTOWTDI

HTH,
M4


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

Date: Wed, 22 Feb 2012 12:47:11 +0000
From: Justin C <justin.1201@purestblue.com>
Subject: Re: a question about efficiency
Message-Id: <fn4f19-lfp.ln1@zem.masonsmusic.co.uk>

On 2012-02-21, Shmuel Metz <spamtrap@library.lspace.org.invalid> wrote:
> In <4f43d60b$0$1387$4fafbaef@reader2.news.tin.it>, on 02/21/2012
>    at 06:36 PM, Kiuhnm <kiuhnm03.4t.yahoo.it> said:
>
>>Of course. What strikes me is that strange "for". 
>
> See statement modifiers in perlsyn.
>
>>"Learning Perl" won't give me too many details until my fragile mind
>>is  ready to assimilate them :)
>
> I found that it was easier to learn from "Programming Perl" than from
> "Learning Perl".

From my non-programming background I found Learning Perl to be
excellent, and *very* accessible. I find PP to be rather dense and,
because of it's size, daunting - I did, though, learn about complex data
structures from that and it blew my mind, I've not picked it up since, I
really should.

   Justin.

-- 
Justin C, by the sea.


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

Date: Wed, 22 Feb 2012 13:10:44 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: a question about efficiency
Message-Id: <87wr7fggiz.fsf@sapphire.mobileactivedefense.com>

gbacon@hiwaay.net (Greg Bacon) writes:
> Kiuhnm <kiuhnm03.4t.yahoo.it> wrote
>
> : [...]
> : Well, theoretically, a closure doesn't need to "capture" outer
> : variables to be called a closure. But you already know that. I guess
> : it depends on how a community see things.
>
> I’m curious to see examples of this usage. Without closing over the
> lexical environment, what’s left is a function pointer.

I've had a look at the CLTLv2 (Common Lisp The Language 2nd ed) of
this yesterday and the usage there was 'a closure is a function
defined in a non-null lexical environment' (paraphrase). There was an
added note that an implementation need not create 'a closure' for a
function defined in such an environment if it can be proven that
nothing from this environment is actually needed and that the
distinction would be more or less pointless since no representation of
'closures' was defined and anything that would really matter was that
lexical scoping works properly (and this was written by the guy who
reportedly invented the term). Consequently, what is or isn't a
closure would be something of interest to the implementation and for
users, its just functions/ subroutines who also observe the rules of
lexical scoping if there are such rules to observe.

From a user perspective, if the term is (technically) useful at all,
it would refer to a subroutine defined in a non-null lexical
environment. Since this isn't the case for anonymous subroutines put
as values into a hash at compile-time in the given way, they are not
closures, the original remark quoted above is besides the point and
IMHO, mainly an attempt to make it appear as if the person who started
this thread wasn't wrong after all by intentionally conufsing readers
(some people pursue such goals with great hardiness).





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

Date: Wed, 22 Feb 2012 13:49:42 +0000
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: a question about efficiency
Message-Id: <87obsr2d1l.fsf@sapphire.mobileactivedefense.com>

Rainer Weikusat <rweikusat@mssgmbh.com> writes:

[...]

> From a user perspective, if the term is (technically) useful at all,
> it would refer to a subroutine defined in a non-null lexical
> environment. Since this isn't the case for anonymous subroutines put
> as values into a hash at compile-time in the given way, they are not
> closures,

This is, of course, completely wrong :-), because there's always 'an
enclosing block' in perl, with 'the current compilation unit' (aka
'file') being the outermost one.


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

Date: Wed, 22 Feb 2012 08:48:05 -0500
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: a question about efficiency
Message-Id: <4f44f215$10$fuzhry+tra$mr2ice@news.patriot.net>

In <ji22it$79h$1@reader1.panix.com>, on 02/22/2012
   at 06:39 AM, tmcd@panix.com (Tim McDaniel) said:

>Unfortunately, too often I've been stuck on servers where I am not 
>a sysadmin or otherwise dare not touch Perl.  I can do modules for
>myself, but that doesn't help with code for others.

Aren't you more likely to find Perl already installed than Python or
Ruby? If you're not allowed to download and install a CPAN module than
I doubt that you'd be allowed to install a new language processor.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org



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

Date: Wed, 22 Feb 2012 08:43:49 -0500
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: a question about efficiency
Message-Id: <4f44f115$9$fuzhry+tra$mr2ice@news.patriot.net>

In <-POdnUXcZo6I-tnSnZ2dnUVZ_q2dnZ2d@posted.hiwaay2>, on 02/21/2012
   at 09:55 PM, gbacon@hiwaay.net (Greg Bacon) said:

>IÔÇÖm

Please check the settings on your news client. Usenet is an ASCII
medium, so anything in other character sets should be MIME encoded. It
looks like you're using UTF-8, in which case I'd recommend an encoding
of QP[1] rather than BASE64.

[1] Bletch!

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org



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

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


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