[30755] in Perl-Users-Digest
Perl-Users Digest, Issue: 2000 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 23 21:09:45 2008
Date: Sun, 23 Nov 2008 18: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 Sun, 23 Nov 2008 Volume: 11 Number: 2000
Today's topics:
Cloning classes, deep copy revisited (Was: Copy Constur sln@netherlands.com
Function calls using ampersand & in Perl, what is it? sln@netherlands.com
Re: How to find all the strings in a long that are at m sln@netherlands.com
Re: How to find all the strings in a long that are at m sln@netherlands.com
Re: How to iterator array in order? <jurgenex@hotmail.com>
Re: How to iterator array in order? sln@netherlands.com
Re: How to iterator array in order? sln@netherlands.com
Re: How to iterator array in order? <someone@example.com>
Re: How to iterator array in order? sln@netherlands.com
Re: How to iterator array in order? <mgjv@heliotrope.com.au>
Re: How to iterator array in order? sln@netherlands.com
Re: How to iterator array in order? <mgjv@heliotrope.com.au>
Re: How to iterator array in order? sln@netherlands.com
Re: How to iterator array in order? <mgjv@heliotrope.com.au>
Re: How to iterator array in order? <jurgenex@hotmail.com>
Re: post increment or pre increment? <hjp-usenet2@hjp.at>
Re: Restarting a Program mid stream xhoster@gmail.com
RFC: Statistics::KernelEstimation - Kernel Density Esti <janert@mailaps.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 23 Nov 2008 20:33:14 GMT
From: sln@netherlands.com
Subject: Cloning classes, deep copy revisited (Was: Copy Consturctor in Perl) ..
Message-Id: <steji4lk2c1i8q27bo415ap2udlniu5770@4ax.com>
I've got a few packages declared in on file. I need a clone/copy
type functionality for all the ones dealing with a high probability
they will be duplicated (but maybe not) in mass. So I need a clone/copy
type functionality. Some classes need 'deep' cloning, some don't.
I came up with this. See any potential problems using this scenario?
I have given all the classes this same mechanism.
Added comments for usenet reading.
Thanks!
sln
-----------------------------------------------------------------
Example:
package ReS;
sub new
{
my $self;
my $class = shift;
if (defined($_[0]) && ref($_[0]) eq 'ReS') {
$self = {};
my $obj = bless ($self, $class);
return copy($obj, $_[0]);
}
$self = {
...
};
# Should we risk calling set_val that does the
# same thing at the expence of a function call ?
# Sure we could do &set_val.. but still overhead
while (my ($name, $val) = splice (@_, 0, 2)) {
next if (!defined $val);
if (exists $self->{lc $name}) {
$self->{lc $name} = $val;
}
}
return bless ($self, $class);
}
sub clone
{
# clone self, return new
return ReS->new( $_[0]);
}
sub copy
{
# copy other to self, return self
return $_[0] unless (defined $_[1] && ref($_[1]) eq 'ReS');
%{$_[0]} = %{$_[1]};
# do specific deep copying..
# see article on dclone function
$_[0]->{'something'} = ();
@{$_[0]->{'something'}} = @{$_[1]->{'something'}};
return $_[0];
}
------------------------------
Date: Sun, 23 Nov 2008 19:35:40 GMT
From: sln@netherlands.com
Subject: Function calls using ampersand & in Perl, what is it?
Message-Id: <eqbji4p3fs7ukjul9l1sjcg1ji2kvh0roj@4ax.com>
According to the doc's it enables the callee to see @_ of
the caller. Is there anything more insidius about this or is that
the extent of & ?
Example:
sub BeginSegStr {return ${&BeginSeg};}
sub BeginSeg
{
# return lvref of begining segment
my $str = "";
return \$str unless (defined $_[1] && ref($_[1]) eq 'SCALAR');
return \substr ${$_[1]}, 0, $_[0]->{'offset'};
}
sln
------------------------------
Date: Sun, 23 Nov 2008 18:54:21 GMT
From: sln@netherlands.com
Subject: Re: How to find all the strings in a long that are at most of n different characters of a test string?
Message-Id: <hc8ji4hothopf8p2h4kbjotf65u48j9k5a@4ax.com>
On Fri, 21 Nov 2008 03:16:49 -0800 (PST), ilovelinux <c7eqjyg02@sneakemail.com> wrote:
>On 21 nov, 04:54, s...@netherlands.com wrote:
>> >>#!/usr/bin/perl
>> >>use strict;
>> >>use warnings;
>>
>> >>my $a =
>> >>'abcdefbacdefabbdefaaaaacdxfaaacdefcdefbacdefabbdefaaaaacdxfaaacdefaacdxfaacdfx';
>> >>my $b = 'aacdxf';
>>
>> >>my $limit = 2;
>> >>my $lenb = length $b;
>>
>> >>print "\nmatching '$a' against '$b'\n";
>>
>> >>while ( $a =~ /(?=(.{$lenb}))/sog ) {
>> >> next if ( $1 ^ $b ) =~ tr/\0//c > $limit;
>> >> print "match '$1' at offset $-[0]\n";
>> >> }
>>
>> >>__END__
>>
>> >Very elegant and fast, but you don't need all the modifiers /sog to the
>> >regex, just /g will do.
>>
>> Actually, he needs 'so' as well. If this is used in a multi-lined
>> way, the '.' needs the 's' modifier if it is possible a '\n' is encounterred
>> and could be part of the pattern.
>> The 'o' suggests to not recompile, which might happen, don't know, anything is
>> possible. By including both, no harm, ho foul.
>
>Harm will be done using the 'o'nce option, when the code is
>transferred to a subroutine and the regexp will be called with $b's of
>different length, because the regexp will be compiled with the first
>$lenb encountered and never change.
>
>Better put the regexp into a variable and use this in the while ():
>
> my $re = qr/(?=(.{$lenb}))/s;
> while ( $a =~ /$re/g ) {
>
>HTH
I never used the /o modifier. Tested it a long time ago and found it
squirley. I only use qr//.
Yes, you are right, the 'o' option lasts the life of the script.
This defies all logic, where is this regexp stored. Is it related to
variables, even lexical ones? This has to be a runtime association on
the first $pattern 'named' variable, even to nested scope lexicals?
I guess its possible.
Over the "life of the script" is all thats mentioned. I think this has
strictly limited use, basically a one time usage.
Docs:
"If $pattern won't be changing over the lifetime of the script,
we can add the //o modifier, which directs perl to only perform
variable substitutions once"
Thanks!
sln
----------------
my $pattern = 'this';
print getmatch_o('this is a test',$pattern)."\n";
$pattern = 'is';
print getmatch_o('this is a test',$pattern)."\n";
sub getmatch_o
{
my ($target,$pattern) = @_;
print $pattern."\n";
my $ttt = $pattern;
my $ggg = $target;
return $1 if ($ggg =~ /($ttt)/o);
return '';
}
__END__
this
this
is
this
------------------------------
Date: Sun, 23 Nov 2008 19:00:48 GMT
From: sln@netherlands.com
Subject: Re: How to find all the strings in a long that are at most of n different characters of a test string?
Message-Id: <j0aji419d57sp9ldadn3fua6jkdn2s8dhn@4ax.com>
On Thu, 20 Nov 2008 23:52:15 GMT, sln@netherlands.com wrote:
>On Thu, 20 Nov 2008 10:06:33 -0800, "John W. Krahn" <someone@example.com> wrote:
>
[snip]
>>while ( $a =~ /(?=(.{$lenb}))/sog ) {
[snip]
>
>I noticed the capture group is in the assertion and it only advances the
>regexp ordinal position by one.
>
>Example:
>
>/(.{$lenb})/ advances 6
>/(?=(.{$lenb}))/ advances 1
>
>I looked in perlre,perlretut and there is only one mention of capture within
>a "non-capture zero-width assertion" extended expression elements.
>That was just a side from some example on (?>..), and that just mentioned,
>the ordinal position is adjusted with a (?=(regex)) analogy.
>
>Do you know why this is?
>
>
>sln
Does anybody know?
sln
------------------------------
Date: Sun, 23 Nov 2008 09:13:19 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: How to iterator array in order?
Message-Id: <bk3ji496aut1ge5host2fvp9pno9ktafv7@4ax.com>
"Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
>On 2008-11-21 05:30, Jürgen Exner <jurgenex@hotmail.com> wrote:
>> BTW: if you are using $#array instead of the length of the array then
>> you probably should also start your iteration with $[ instead of with 0.
>> The combination you are using doesn't make much sense because your start
>> value is hardcoded to ignores non-default values for $[ while your end
>> respects them.
>
>Frankly, in my world $[ doesn't exist. Anyone who sets it outside of an
>obfu, should be drawn and quartered.
Agreed :-)
>I won't clutter up my code just
>because some idiot might set it. So if I need to iterate over the
>indices of an array I use:
>
> for my $i (0 .. $#array) { ... }
Why not
for my $i (0 .. @array+1)
Doesn't seem to introduce much clutter to me...
jue
>
> hp
------------------------------
Date: Sun, 23 Nov 2008 19:11:26 GMT
From: sln@netherlands.com
Subject: Re: How to iterator array in order?
Message-Id: <rfaji4d82e5m10a6b2n2565vj8laud59h6@4ax.com>
On Fri, 21 Nov 2008 11:02:07 -0500, Uri Guttman <uri@stemsystems.com> wrote:
>>>>>> "s" == sln <sln@netherlands.com> writes:
>
> s> On Thu, 20 Nov 2008 20:39:04 -0800 (PST), Peng Yu <PengYu.UT@gmail.com> wrote:
> >> foreach(@array) {
> >> print "$_\n";
> >> }
> >>
> >> for my $elem (@array) {
> >> print "$elem\n";
> >> }
> >>
> >> for($i = 0; $i <= $#array; ++ $i) {
> >> print "$array[$i]\n";
> >> }
>
> s> Yes, all three would. The 'foreach' is a special,
> s> unrelated case. The target becomes an alias for the
> s> actual element. If you write to the target, you write
> s> to the element, be careful on that one.
>
>huh? for and foreach are EXACTLY the same in perl - they are aliases for
>the same syntax spot. the type of loop is controlled by the presence of
>; inside the (). you have either a list loop (the first two examples) or
>a c style loop (the last example).
>
>the first two examples are the same except for using $_ vs a
>lexical. the 'for' vs 'foreach' there is irrelevent (try it). both alias
>each element to the loop variable.
>
>uri
Really good to know. I will try it, I will put it on the queue of 10,000
other things to try. Until I do, I must take your word for it and be sure
to not asign to $_ unless inside a while() loop. Sound good?
$@_,$_,$_[n] still got me cornfused.
sln
------------------------------
Date: Sun, 23 Nov 2008 19:21:41 GMT
From: sln@netherlands.com
Subject: Re: How to iterator array in order?
Message-Id: <k3bji4plau6om1eti2smknsofatjduh7jt@4ax.com>
On Thu, 20 Nov 2008 20:39:04 -0800 (PST), Peng Yu <PengYu.UT@gmail.com> wrote:
>Hi,
>
>I know at least three ways to iterator an array. But I'm not sure if
>the first two iteration methods would iterator the array in order
>(from the first element to the last element). Can somebody let me
>know?
>
>What is the best way to iterator an array?
>
>Thanks,
>Peng
>
>#!/usr/bin/perl
>
>@array = (1, 2, 3, 4);
>
>foreach(@array) {
> print "$_\n";
>}
>
>for my $elem (@array) {
> print "$elem\n";
>}
>
>for($i = 0; $i <= $#array; ++ $i) {
^^
Don't do this here, it just looks bad.
As a C++ programmer, you know the problems with
compiler optimizations on pre-increment.
In Perl its ok, no such thing as optimizations.
$i = ++$i is ok.
sln
------------------------------
Date: Sun, 23 Nov 2008 11:31:32 -0800
From: "John W. Krahn" <someone@example.com>
Subject: Re: How to iterator array in order?
Message-Id: <ociWk.31291$8T2.5709@newsfe07.iad>
J=FCrgen Exner wrote:
> "Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
>> On 2008-11-21 05:30, J=FCrgen Exner <jurgenex@hotmail.com> wrote:
>=20
>>> BTW: if you are using $#array instead of the length of the array then=
>>> you probably should also start your iteration with $[ instead of with=
0.
>>> The combination you are using doesn't make much sense because your st=
art
>>> value is hardcoded to ignores non-default values for $[ while your en=
d
>>> respects them.
>> Frankly, in my world $[ doesn't exist. Anyone who sets it outside of a=
n
>> obfu, should be drawn and quartered.=20
>=20
> Agreed :-)
>=20
>> I won't clutter up my code just
>> because some idiot might set it. So if I need to iterate over the
>> indices of an array I use:
>>
>> for my $i (0 .. $#array) { ... }
>=20
> Why not=20
Why not indeed!
> for my $i (0 .. @array+1)=20
> Doesn't seem to introduce much clutter to me...
Just errors. :(
John
--=20
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
------------------------------
Date: Sun, 23 Nov 2008 20:06:15 GMT
From: sln@netherlands.com
Subject: Re: How to iterator array in order?
Message-Id: <brdji4tbe0nm6ved3cdmvvsm9ih6thncer@4ax.com>
On Sun, 23 Nov 2008 11:31:32 -0800, "John W. Krahn" <someone@example.com> wrote:
>Jürgen Exner wrote:
>> "Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
>>> On 2008-11-21 05:30, Jürgen Exner <jurgenex@hotmail.com> wrote:
>>
>>>> BTW: if you are using $#array instead of the length of the array then
>>>> you probably should also start your iteration with $[ instead of with 0.
>>>> The combination you are using doesn't make much sense because your start
>>>> value is hardcoded to ignores non-default values for $[ while your end
>>>> respects them.
>>> Frankly, in my world $[ doesn't exist. Anyone who sets it outside of an
>>> obfu, should be drawn and quartered.
>>
>> Agreed :-)
>>
>>> I won't clutter up my code just
>>> because some idiot might set it. So if I need to iterate over the
>>> indices of an array I use:
>>>
>>> for my $i (0 .. $#array) { ... }
>>
>> Why not
>
>Why not indeed!
>
>> for my $i (0 .. @array+1)
>> Doesn't seem to introduce much clutter to me...
>
>Just errors. :(
>
>
>John
Errors?
asdf:>> for my $i (0 .. @array+1)
Give an example please.
sln
------------------------------
Date: Mon, 24 Nov 2008 07:25:09 +1100
From: Martien Verbruggen <mgjv@heliotrope.com.au>
Subject: Re: How to iterator array in order?
Message-Id: <slrngijf15.70r.mgjv@mgjv.heliotrope.home>
On Sun, 23 Nov 2008 20:06:15 GMT,
sln@netherlands.com <sln@netherlands.com> wrote:
> On Sun, 23 Nov 2008 11:31:32 -0800, "John W. Krahn"
> <someone@example.com> wrote:
>
>>Jürgen Exner wrote:
>>> "Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
>>>> On 2008-11-21 05:30, Jürgen Exner <jurgenex@hotmail.com> wrote:
>>>
>>>>> BTW: if you are using $#array instead of the length of the array then
>>>>> you probably should also start your iteration with $[ instead of with 0.
>>>>> The combination you are using doesn't make much sense because your start
>>>>> value is hardcoded to ignores non-default values for $[ while your end
>>>>> respects them.
>>>> Frankly, in my world $[ doesn't exist. Anyone who sets it outside of an
>>>> obfu, should be drawn and quartered.
>>>
>>> Agreed :-)
>>>
>>>> I won't clutter up my code just
>>>> because some idiot might set it. So if I need to iterate over the
>>>> indices of an array I use:
>>>>
>>>> for my $i (0 .. $#array) { ... }
>>>
>>> Why not
>>
>>Why not indeed!
>>
>>> for my $i (0 .. @array+1)
>>> Doesn't seem to introduce much clutter to me...
>>
>>Just errors. :(
>>
>>
>>John
> Errors?
> asdf:>> for my $i (0 .. @array+1)
$ perl -wl
my @foo = (1, 2, 3);
print "\$#foo and \@foo + 1 are ",
($#foo == @foo + 1) ? "" : "not ",
"the same";
__END__
Martien
--
|
Martien Verbruggen | life ain't fair, but the root password
| helps. -- BOFH
|
------------------------------
Date: Sun, 23 Nov 2008 20:38:49 GMT
From: sln@netherlands.com
Subject: Re: How to iterator array in order?
Message-Id: <jmfji4hdien19rnmpnghmkb71kqjt051ho@4ax.com>
On Mon, 24 Nov 2008 07:25:09 +1100, Martien Verbruggen <mgjv@heliotrope.com.au> wrote:
>On Sun, 23 Nov 2008 20:06:15 GMT,
> sln@netherlands.com <sln@netherlands.com> wrote:
>> On Sun, 23 Nov 2008 11:31:32 -0800, "John W. Krahn"
>> <someone@example.com> wrote:
>>
[snip]
>>>> for my $i (0 .. @array+1)
>>>> Doesn't seem to introduce much clutter to me...
>>>
>>>Just errors. :(
>>>
>>>
>>>John
>> Errors?
>> asdf:>> for my $i (0 .. @array+1)
>
>$ perl -wl
>my @foo = (1, 2, 3);
>print "\$#foo and \@foo + 1 are ",
> ($#foo == @foo + 1) ? "" : "not ",
> "the same";
>__END__
>
>Martien
Who said $#foo and \@foo + 1 are the same amount??
for my $i (0 .. @array+1)...
'@array+1' is just a number. Any other errors?
sln
------------------------------
Date: Mon, 24 Nov 2008 08:01:06 +1100
From: Martien Verbruggen <mgjv@heliotrope.com.au>
Subject: Re: How to iterator array in order?
Message-Id: <slrngijh4i.70r.mgjv@mgjv.heliotrope.home>
On Sun, 23 Nov 2008 20:38:49 GMT,
sln@netherlands.com <sln@netherlands.com> wrote:
> On Mon, 24 Nov 2008 07:25:09 +1100, Martien Verbruggen
> <mgjv@heliotrope.com.au> wrote:
>
>>On Sun, 23 Nov 2008 20:06:15 GMT,
>> sln@netherlands.com <sln@netherlands.com> wrote:
>>> On Sun, 23 Nov 2008 11:31:32 -0800, "John W. Krahn"
>>> <someone@example.com> wrote:
>>>
> [snip]
>>>>> for my $i (0 .. @array+1)
>>>>> Doesn't seem to introduce much clutter to me...
>>>>
>>>>Just errors. :(
>>>>
>>>>
>>>>John
>>> Errors?
>>> asdf:>> for my $i (0 .. @array+1)
>>
>>$ perl -wl
>>my @foo = (1, 2, 3);
>>print "\$#foo and \@foo + 1 are ",
>> ($#foo == @foo + 1) ? "" : "not ",
>> "the same";
>>__END__
>>
>>Martien
>
> Who said $#foo and \@foo + 1 are the same amount??
Jürgen Exner did, implicitly. He wrote the first bit of code above (you
snipped the attribution, but left that code), in response to someone
else writing a loop with $#array, in code that I quoted in the previous
message, but that you snipped.
> for my $i (0 .. @array+1)...
>
> '@array+1' is just a number. Any other errors?
But it's the wrong number for this context. Not all numbers are
equivalent in all contexts.
Even without the original code, @array + 1 is an index that is too high
by two for the size of the array it's supposed to be indexing.
I don't see any other errors, but I think this error on its own is
enough to be commented on.
Martien
--
|
Martien Verbruggen | Never hire a poor lawyer. Never buy from a
| rich salesperson.
|
------------------------------
Date: Sun, 23 Nov 2008 23:26:57 GMT
From: sln@netherlands.com
Subject: Re: How to iterator array in order?
Message-Id: <lbpji4drigql8vcd6e9132h5de6qmp7egi@4ax.com>
On Mon, 24 Nov 2008 08:01:06 +1100, Martien Verbruggen <mgjv@heliotrope.com.au> wrote:
>On Sun, 23 Nov 2008 20:38:49 GMT,
> sln@netherlands.com <sln@netherlands.com> wrote:
>> On Mon, 24 Nov 2008 07:25:09 +1100, Martien Verbruggen
>> <mgjv@heliotrope.com.au> wrote:
>>
>>>On Sun, 23 Nov 2008 20:06:15 GMT,
>>> sln@netherlands.com <sln@netherlands.com> wrote:
>>>> On Sun, 23 Nov 2008 11:31:32 -0800, "John W. Krahn"
>>>> <someone@example.com> wrote:
>>>>
>> [snip]
>>>>>> for my $i (0 .. @array+1)
>>>>>> Doesn't seem to introduce much clutter to me...
>>>>>
>>>>>Just errors. :(
>>>>>
>>>>>
>>>>>John
>>>> Errors?
>>>> asdf:>> for my $i (0 .. @array+1)
>>>
>>>$ perl -wl
>>>my @foo = (1, 2, 3);
>>>print "\$#foo and \@foo + 1 are ",
>>> ($#foo == @foo + 1) ? "" : "not ",
>>> "the same";
>>>__END__
>>>
>>>Martien
>>
>> Who said $#foo and \@foo + 1 are the same amount??
>
>Jürgen Exner did, implicitly. He wrote the first bit of code above (you
>snipped the attribution, but left that code), in response to someone
>else writing a loop with $#array, in code that I quoted in the previous
>message, but that you snipped.
>
>> for my $i (0 .. @array+1)...
>>
>> '@array+1' is just a number. Any other errors?
>
>But it's the wrong number for this context. Not all numbers are
>equivalent in all contexts.
>
>Even without the original code, @array + 1 is an index that is too high
>by two for the size of the array it's supposed to be indexing.
>
>I don't see any other errors, but I think this error on its own is
>enough to be commented on.
>
>Martien
There was no context mentioned. I got no problem with
the range. In fact, in my opinion,
for my $i (0 .. @array+65535)
is way better than
for my $i (0 .. $#array)
it clearly states the truth about the size of arrays !!
Have a nice day!
sln
------------------------------
Date: Mon, 24 Nov 2008 11:29:29 +1100
From: Martien Verbruggen <mgjv@heliotrope.com.au>
Subject: Re: How to iterator array in order?
Message-Id: <slrngijtb9.70r.mgjv@mgjv.heliotrope.home>
On Sun, 23 Nov 2008 23:26:57 GMT,
sln@netherlands.com <sln@netherlands.com> wrote:
> There was no context mentioned. I got no problem with
There was. Please check the thread.
> the range. In fact, in my opinion,
> for my $i (0 .. @array+65535)
> is way better than
> for my $i (0 .. $#array)
>
> it clearly states the truth about the size of arrays !!
That is just plain silly.
Martien
--
|
Martien Verbruggen | In the fight between you and the world, back
| the world - Franz Kafka
|
------------------------------
Date: Sun, 23 Nov 2008 18:03:14 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: How to iterator array in order?
Message-Id: <um2ki4p07rvf0063gpupc2ujpk07g4jhhg@4ax.com>
"John W. Krahn" <someone@example.com> wrote:
>Jürgen Exner wrote:
>> "Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
>>> On 2008-11-21 05:30, Jürgen Exner <jurgenex@hotmail.com> wrote:
>>> for my $i (0 .. $#array) { ... }
>>
>> Why not
>
>Why not indeed!
>
>> for my $i (0 .. @array+1)
>> Doesn't seem to introduce much clutter to me...
>
>Just errors. :(
Well, yeah, fine, whatever.
s/+/-/
I guess it was pretty obvious what I meant. If you want to make a big
deal out of that typo, then be my guest.
jue
------------------------------
Date: Mon, 24 Nov 2008 00:44:25 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: post increment or pre increment?
Message-Id: <slrngijqmq.ci4.hjp-usenet2@hrunkner.hjp.at>
On 2008-11-23 14:05, News123 <news123@free.fr> wrote:
> Hi Peter,
>
> Is this a copy paste error?
Yes. But unfortunately it is a copy & paste error I made in the test
script, and not just in the posting, so pre and post
being roughly the same speed was to be expected.
> You seem to test twice the pre-increment:
>
>> {
>> 'pre' => sub { for(my $i = 0; $i <N; ++ $i) {} },
>> 'post' => sub { for(my $i = 0; $i <N; ++ $i) {} },
>> 'range' => sub { for my $i (0 .. N-1) {} },
>
However, if I fix it:
'pre' => sub { for(my $i = 0; $i <N; ++ $i) {} },
'post' => sub { for(my $i = 0; $i <N; $i++) {} },
'range' => sub { for my $i (0 .. N-1) {} },
and then run it through -MO=Deparse, the result shows that the optimizer
simplifies $i++ to ++$i:
use Benchmark (':hireswallclock', 'cmpthese');
use constant ('N', 14);
use warnings;
use strict 'refs';
cmpthese(-2, {'pre', sub {
for (my $i = 0; $i < 14; ++$i) {
();
}
}
, 'post', sub {
for (my $i = 0; $i < 14; ++$i) {
();
}
}
, 'range', sub {
foreach my $i (0 .. 13) {
();
}
}
});
foo syntax OK
So, since both generate the same code, they should still be the same speed ;-).
hp
------------------------------
Date: 23 Nov 2008 21:40:30 GMT
From: xhoster@gmail.com
Subject: Re: Restarting a Program mid stream
Message-Id: <20081123164112.777$75@newsreader.com>
pgodfrin <pgodfrin@gmail.com> wrote:
> Greetings,
> I have a perl program that has multiple steps. I'd like to be able to
> restart it at any step.
I'd generally implement this as several different scripts, with one
meta script (Perl or shell) that invokes them in turn.
> This works:
>
> #!/bin/perl
> goto $ARGV[0]; # forgive me
> S1:
> {
> print "S1\n";
> exit;
> }
> S2:
> {
> print "S2\n";
> exit;
> }
>
> However, I was wondering if there is any programmatic access to the
> name of the block. That way I could print the name of the block
> instead of hard-coding an arbitrary value (print "S1\n")
I can't think of a way that is not a major re-org of your code, or
worse yet a source filter.
Since the name of the block is an arbitrary value to start with,
including that arbitrary value in one other place "by hand" doesn't
seem like too much of a burden. I would think it less of a sin than
using goto in the first place.
Out of curiosity, how to do you plan to pass data between blocks? How will
you know if a block completed successfully or not? If S1 starts but then
dies before finishing, is it safe to restart on S2?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Sun, 23 Nov 2008 13:46:34 -0800 (PST)
From: pkj <janert@mailaps.org>
Subject: RFC: Statistics::KernelEstimation - Kernel Density Estimates and Histograms
Message-Id: <0325770e-39dd-42bd-88ef-fbf2d0cd85fb@q30g2000prq.googlegroups.com>
I would like to invite comments on a new module, named
Statistics::KernelEstimation.
This modules calculates Kernel Density Estimates and related
quantities for a collection of random points.
A Kernel Density Estimate (KDE) is similar to a histogram,
but improves on two known problems of histograms: it is
smooth (whereas a histogram is ragged) and does not suffer
from ambiguity in regards to the placement of bins.
In a KDE, a smooth, strongly peaked function is placed at the
location of each point in the collection, and the contributions
from all points is summed. The resulting function is a smooth
approximation to the probability density from which the set of
points was drawn.
This module calculates KDEs as well as Cumulative Density
Functions (CDF). Three different kernels are available
(Gaussian, Box, Epanechnikov).
The module also includes limited support for bandwidth optimization.
Finally, the module can generate "classical" histograms and
distribution functions.
The full POD is available here:
http://www.beyondcode.org/projects/kernelestimation/
Let me know what you think!
------------------------------
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 V11 Issue 2000
***************************************