[32059] in Perl-Users-Digest
Perl-Users Digest, Issue: 3323 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 16 11:09:28 2011
Date: Wed, 16 Mar 2011 08:09:08 -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 Wed, 16 Mar 2011 Volume: 11 Number: 3323
Today's topics:
App::JobLog and App::Nag namespaces <dfhoughton@gmail.com>
Re: Autovivification <derykus@gmail.com>
C Compiler question <dave@invalid.invalid>
Re: C Compiler question <tadmc@seesig.invalid>
Re: C Compiler question <dave@invalid.invalid>
Re: C Compiler question <tadmc@seesig.invalid>
Re: convenient module to take statistics for hashed str <nospam.gravitalsun@hotmail.com.nospam>
Re: convenient module to take statistics for hashed str <ela@yantai.org>
Re: recursive Pythagorian triples <willem@toad.stack.nl>
Re: recursive Pythagorian triples <bugbear@trim_papermule.co.uk_trim>
Re: recursive Pythagorian triples <willem@toad.stack.nl>
Re: recursive Pythagorian triples <justin.1102@purestblue.com>
Re: recursive Pythagorian triples <cartercc@gmail.com>
Re: recursive Pythagorian triples <cartercc@gmail.com>
Re: recursive Pythagorian triples <ednotover@gmail.com>
Re: recursive Pythagorian triples <hjp-usenet2@hjp.at>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 16 Mar 2011 07:38:34 -0700 (PDT)
From: dfhoughton <dfhoughton@gmail.com>
Subject: App::JobLog and App::Nag namespaces
Message-Id: <9ff1267c-a367-4d31-9e6d-7881bac5069d@y31g2000prd.googlegroups.com>
Hi. I recently decided, after having used Perl for years, to put a few
modules on CPAN. I had time, being recently laid off, it would stretch
my abilities a bit, and I thought I could give something back. So I
went ahead and did it. Two distributions are up there now:
http://search.cpan.org/~dfh/
Then I read the documentation at PAUSE more and realized I didn't
follow protocol and should have asked about the namespaces first (I
did look first for functionality overlap with any existing modules on
CPAN and didn't find it). So, I figured better late than never. Could
you advise me whether these are reasonable namespace choices?
A bit about the distributions:
App::Nag
App::Nag is a little command line reminder utility. If you install it
you get an executable called "nag" and the modules App::Nag and
App::Nag::Slap. You send yourself reminders to pop up after a fixed
interval or at a specified time and you tell it how annoying to make
the reminder. When the time is up you get the reminder. E.g.,
nag 15m put bread in oven
or
nag --slap 2:55pm go get kids
It's pretty simple, mostly a wrapper around other modules. I wanted a
reminder utility like this. The ones I'd been using weren't doing the
trick. So I wrote this. Now my loaves aren't so lofty and my kids are
less neglected.
App::JobLog
As its name suggests, this is an application that lets you log the
hours you've worked. It's main nice feature, in my opinion, is that it
understands all sort of English natural language expressions for dates
or periods of time, so it's easy to extract reports. It understands
"ever", "last year", "last month", "this week", "Feb 2010", "Feb 1 -
14", "last Friday", "Wednesday", "pay period", etc. For example:
houghton@NorthernSpy:~$ job s yesterday
Tuesday, 15 March
11:33 - 11:35 am 0.04 C******n checking up on Mort's issue with
pipeline
11:38 - 11:46 am 0.12 C******n checking up on Mort's issue with
pipeline; figuring out null pointer in multi-threaded
code
12:40 - 1:11 pm 0.52 C******n debugging null
pointers
TOTAL HOURS 0.68
C******n 0.68
(tag munged to protect the innocent and it looks better on a screen
with a fixed width font)
App::JobLog installs the executable "job". This is pretty similar to
"jobs", but doesn't seem to clash with any common existing utilities,
at least on Ubuntu, which I'm using as representative of the Unix
ecosystem, whose command line utilities I imagine are a superset of
what you're likely to find on a Mac or Windows. It also installs a
large number of modules in the App::JobLog namespace. Most of these
are dependent to one degree or another on other modules in the
namespace. Those one most likely to be useful as separate library is
App::JobLog::TimeGrammar, which interprets the natural language time
expressions. Unfortunately, in order to get it to understand "pay
period", I wired it a bit to App::JobLog::Config. I'll consider how
better to separate these two in the future.
So, I'd appreciate any comments. I'll take silence as evidence that no
one has any problem with my use of the namespaces. Thanks.
David Houghton
------------------------------
Date: Wed, 16 Mar 2011 03:58:01 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: Autovivification
Message-Id: <e9a407b2-8472-4d95-b0e1-8c372689aea2@i39g2000prd.googlegroups.com>
On Mar 15, 11:00=A0pm, "Uri Guttman" <u...@StemSystems.com> wrote:
> >>>>> "CD" =3D=3D C DeRykus <dery...@gmail.com> writes:
>
> =A0 CD> On Mar 15, 8:15 pm, "Uri Guttman" <u...@StemSystems.com> wrote:
> =A0 >> >>>>> "PJH" =3D=3D Peter J Holzer <hjp-usen...@hjp.at> writes:
> =A0 >> ...
>
> =A0 CD> But this issue still lurks:
>
> =A0 PJH> But this is a sideline. My orginal gripe was
> =A0 PJH> that the behaviour between $x->[0][0] and
> =A0 PJH> @{ $x->[0] } was inconsistent (autovivification
> =A0 PJH> in one case but not the other). If your argument
> =A0 PJH> is that this should be different because Perl
> =A0 PJH> CAN tell the difference then I suspect that all
> =A0 PJH> your arguments boil down to "it must be this way
> =A0 PJH> because it is so".
>
> =A0 CD> Even a slight simplification demo's the seeming
> =A0 CD> inconsistency:
>
> =A0 CD> =A0 perl -Mstrict -wle 'my $foo;print $foo->[0]'
> =A0 CD> =A0 =A0 =A0vs.
> =A0 CD> =A0 perl -Mstrict -wle 'my $foo;print @{$foo->[0]}'
> =A0 CD> =A0 Can't use an undefined value as an ARRAY ref...
>
> =A0 CD> You might reasonably think that either both should
> =A0 CD> work or both should fail.
>
> try dropping the strict and printing $foo
>
> perl -wle 'my $foo;print @{$foo->[0]}; print "$foo\n"'
> Use of uninitialized value in array dereference at -e line 1.
>
> ARRAY(0x691df0)
>
> so it didautoviv$foo. the warning/strict error was from the @{}
> part. and that is correct. there is no inconsistancy here.autovivis
> when you have lvalue situations, explicit or implied. $foo->[0] part is
> neither so it doesn't get autovivified. a single level dereference
> doesn't get autovivified. you need depth or an lvalue.
>
Ah, good explanation. There's almost an optical
illusion for the unwary since @{$foo->[0]} so
nearly resembles the ref. chain $foo->[0][0]
that does get autovivified.
And, though the former has no depth, it still
works as an lvalue:
perl -Mstrict -wle 'my $foo;print @{$foo->[0]} =3D()'
--
Charles DeRykus
------------------------------
Date: Wed, 16 Mar 2011 11:07:13 +0000 (UTC)
From: "Dave Saville" <dave@invalid.invalid>
Subject: C Compiler question
Message-Id: <fV45K0OBJxbE-pn2-jLiMINwzQHhK@localhost>
When one installs perl does it "remember" anything about the C
compiler, .h files and libs at the time?
Because on my ECS OS/2 system running perl 5.8.2 I can install most
modules from CPAN without a problem, *unless* the install needs to run
the C compiler and then they usually fall over with some obscure
error. Most often it is a linkage error rather than the compiler
whingeing. I *have* updated the C compiler several times since
installing perl hence the question.
TIA
--
Regards
Dave Saville
------------------------------
Date: Wed, 16 Mar 2011 06:51:13 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: C Compiler question
Message-Id: <slrnio18o2.ut0.tadmc@tadbox.sbcglobal.net>
Dave Saville <dave@invalid.invalid> wrote:
> When one installs perl does it "remember" anything about the C
> compiler, .h files and libs at the time?
Yes.
perl -V
...
Compiler:
...
Linker and Libraries:
...
Dynamic Linking:
...
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Wed, 16 Mar 2011 14:03:02 +0000 (UTC)
From: "Dave Saville" <dave@invalid.invalid>
Subject: Re: C Compiler question
Message-Id: <fV45K0OBJxbE-pn2-1fcElvNEdkji@localhost>
On Wed, 16 Mar 2011 11:51:13 UTC, Tad McClellan <tadmc@seesig.invalid>
wrote:
> Dave Saville <dave@invalid.invalid> wrote:
>
> > When one installs perl does it "remember" anything about the C
> > compiler, .h files and libs at the time?
>
>
> Yes.
>
> perl -V
>
> ...
> Compiler:
> ...
> Linker and Libraries:
> ...
> Dynamic Linking:
> ...
>
>
OK Thanks - So how do I update them if needed after a compiler update?
--
Regards
Dave Saville
------------------------------
Date: Wed, 16 Mar 2011 09:47:31 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: C Compiler question
Message-Id: <slrnio1j2k.v7k.tadmc@tadbox.sbcglobal.net>
Dave Saville <dave@invalid.invalid> wrote:
> On Wed, 16 Mar 2011 11:51:13 UTC, Tad McClellan <tadmc@seesig.invalid>
> wrote:
>
>> Dave Saville <dave@invalid.invalid> wrote:
>>
>> > When one installs perl does it "remember" anything about the C
>> > compiler, .h files and libs at the time?
>>
>>
>> Yes.
>>
>> perl -V
>>
>> ...
>> Compiler:
>> ...
>> Linker and Libraries:
>> ...
>> Dynamic Linking:
>> ...
>>
>>
>
> OK Thanks - So how do I update them if needed after a compiler update?
recompile the perl binary.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Wed, 16 Mar 2011 10:44:52 +0200
From: "George Mpouras" <nospam.gravitalsun@hotmail.com.nospam>
Subject: Re: convenient module to take statistics for hashed structures?
Message-Id: <ilpt8p$2uv$1@news.ntua.gr>
> I wanna change your implementation from "discrete" checking to
> "continuous" one, the logic is to first sort (rank keys: *** expected
> range: (0-100] ***) numerically, then test if the "largest" key (e.g. 100,
> 75 etc) is larger than the threshold specified. My problem is that I don't
> know how to refer to the keys under
>
> $data{$_[0]}->[1]->[$i]->[1]
>
> Writing something like "foreach my $field (sort {$b<=>$a} keys
> %data{$_[0]}->[1]->[$i]->[1])" (Thanks for McClellan's teaching on
> appropriately using sort here) does not work. Moreover, there's no need to
> "foreach" here as if the largest one also can't surpass the threshold,
> neither the smaller ones can. So how to avoid "foreach" here?
>
For the data
ID|B|C|D|E|F|G|H
01|3|7|9|3|4|2|3
01|3|7|9|3|4|2|2
01|3|7|9|5|8|6|6
01|3|7|9|3|4|2|3
02|4|7|9|3|4|2|1
02|4|7|9|3|4|2|2
02|4|7|9|3|4|2|3
02|4|7|9|3|4|2|3
what would be your input and what do you expect ?
An example make things more clear.
------------------------------
Date: Wed, 16 Mar 2011 18:14:20 -0700
From: "ela" <ela@yantai.org>
Subject: Re: convenient module to take statistics for hashed structures?
Message-Id: <ilpuuv$i8e$1@ijustice.itsc.cuhk.edu.hk>
"George Mpouras" <nospam.gravitalsun@hotmail.com.nospam> wrote in message
news:ilpt8p$2uv$1@news.ntua.gr...
>> I wanna change your implementation from "discrete" checking to
>> "continuous" one, the logic is to first sort (rank keys: *** expected
>> range: (0-100] ***) numerically, then test if the "largest" key (e.g.
>> 100, 75 etc) is larger than the threshold specified. My problem is that I
>> don't know how to refer to the keys under
>>
>> $data{$_[0]}->[1]->[$i]->[1]
>>
>> Writing something like "foreach my $field (sort {$b<=>$a} keys
>> %data{$_[0]}->[1]->[$i]->[1])" (Thanks for McClellan's teaching on
>> appropriately using sort here) does not work. Moreover, there's no need
>> to "foreach" here as if the largest one also can't surpass the threshold,
>> neither the smaller ones can. So how to avoid "foreach" here?
>>
>
>
> For the data
>
> ID|B|C|D|E|F|G|H
> 01|3|7|9|3|4|2|3
> 01|3|7|9|3|4|2|2
> 01|3|7|9|5|8|6|6
> 01|3|7|9|3|4|2|3
> 02|4|7|9|3|4|2|1
> 02|4|7|9|3|4|2|2
> 02|4|7|9|3|4|2|3
> 02|4|7|9|3|4|2|3
>
> what would be your input and what do you expect ?
> An example make things more clear.
>
Dear George,
First of all, I really appreciate your accomodating character. Well, from
your example, what I expect is that, providing a threshold of 100%, for
ID=01, then by looking up the table, H, then G, F, E fail; and then D=9
should return. And if threshold of 70% is given, then H fails (50% for two
3's) but G=2 (three 2's, 75% > 70%) should return. The same threshold will
be used for all the million rows that may have up to 100k unique ID's. So in
this case, 70% threshold will make analysis for ID=02 also return G=2.
------------------------------
Date: Wed, 16 Mar 2011 08:54:56 +0000 (UTC)
From: Willem <willem@toad.stack.nl>
Subject: Re: recursive Pythagorian triples
Message-Id: <slrnio0un0.bv9.willem@toad.stack.nl>
ccc31807 wrote:
) On Mar 15, 2:49?pm, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
)> Not sure why you would want to do this,
)
) Because of this, an Erlang program to find Pythagorian triples
) recursively:
)
) pythag(N) ->
) [{A,B,C} ||
) A <- seq(1,N),
) B <- seq(1,N),
) C <- seq(1,N),
) A + B + C =< N,
) (A * A) + (B * B) =:= C * C].
)
) This says, given an integer N, for every permutation of A, B, and C
) such that A+B+C is less than N, return A, B, C if the condition is
) true.
And how is that recursion ?
) I wondered if Perl could do the same in as few lines of code, taking
) into account the function seq(N1,N2) which returns successive integers
) from N1 to N2.
for my $A (1..$N) {
for my $B (1..$N) {
for my $C (1..$N) {
print "$A,$B,$C\n" if $A+$B+$C<$N and ($A*$A)+($B*$B)==($C*$C);
}
}
}
Is the same in as few lines of code. 100% straightforward.
Iterating over the C variable is extremely silly, by the way.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Wed, 16 Mar 2011 09:07:45 +0000
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: recursive Pythagorian triples
Message-Id: <YI2dnSSSTvV84B3QnZ2dnUVZ8q-dnZ2d@brightview.co.uk>
ccc31807 wrote:
> On Mar 15, 2:49 pm, "Peter J. Holzer"<hjp-usen...@hjp.at> wrote:
>> Not sure why you would want to do this,
>
> Because of this, an Erlang program to find Pythagorian triples
> recursively:
>
> pythag(N) ->
> [{A,B,C} ||
> A<- seq(1,N),
> B<- seq(1,N),
> C<- seq(1,N),
> A + B + C =< N,
> (A * A) + (B * B) =:= C * C].
It's an interesting use of language features, but an
extremely lousy way of finding pythagorean triples.
See rest of thread!
BugBear
------------------------------
Date: Wed, 16 Mar 2011 09:59:20 +0000 (UTC)
From: Willem <willem@toad.stack.nl>
Subject: Re: recursive Pythagorian triples
Message-Id: <slrnio12fo.22hh.willem@toad.stack.nl>
ccc31807 wrote:
) Pythagorian triples are integers that form the sides of a right
) triangle, e.g., 3, 4, 5. I've posted an iterative version below for
) all triples less than 100. I'm having trouble coming up with a
) recursive version. Any ideas?
Why would you want a recursive version anyway ?
Here's a balanced line version that only uses addition:
sub pythag {
my ($a, $b, $c, $a2b2, $c2) = @_;
while ($a < $b) {
while ($c2 < $a2b2) {
$c2 += $c + $c + 1;
$c++;
}
last if $c > 100;
print "$a - $b - $c\n" if ($c2 == $a2b2);
$a2b2 += $a + $a + 1;
$a++;
}
}
my $a2b2 = 2;
for my $b (1 .. 100) {
pythag (1, $b, 1, $a2b2, 1);
$a2b2 += $b + $b + 1;
}
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Wed, 16 Mar 2011 11:01:25 +0000
From: Justin C <justin.1102@purestblue.com>
Subject: Re: recursive Pythagorian triples
Message-Id: <5th658-gs4.ln1@zem.masonsmusic.co.uk>
On 2011-03-15, ccc31807 <cartercc@gmail.com> wrote:
> #! perl
> use strict;
> use warnings;
> print "Pythagorian triples\n\n";
>
> for(my $i = 1; $i < 101; $i++)
> {
> for(my $j = 1; $j < 101; $j++)
> {
> for(my $k = 1; $k < 101; $k++)
> {
> print "$i - $j - $k\n" if ($i * $i + $j * $j) == ($k * $k);
> }
> }
> }
This isn't my strong point, but why would you do `$i = $j = $k = 1` when
they can never be the same. In addition, if you want $k < 101, then $i
cannot be > 99 and $j cannot be > 100, they're not pythagorean trips as
I understand them if any numbers are duplicated in a set.
Does the above not iterate over all matches even if done:
for (my $i = 3; $i < 99; $i++) {
for (my $j = $i + 1; $j < 100; $j++) {
for (my $k = $j + 1; $k < 101; $k++) {
print "$i - $j - $k\n" if ($i**2 + $j**2) == $k**2;
}
}
}
I think this avoids duplicates too.
What I don't understand is recursion in this context.
Justin.
--
Justin C, by the sea.
------------------------------
Date: Wed, 16 Mar 2011 06:46:00 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: recursive Pythagorian triples
Message-Id: <c3ea2ab6-9edd-4cd6-9dd9-ba4b37abf451@i35g2000prd.googlegroups.com>
On Mar 15, 8:12=A0pm, sreservoir <sreserv...@gmail.com> wrote:
> > pythag(N) ->
> > =A0 =A0 =A0[{A,B,C} ||
> > =A0 =A0 =A0 =A0 =A0A<- seq(1,N),
> > =A0 =A0 =A0 =A0 =A0B<- seq(1,N),
> > =A0 =A0 =A0 =A0 =A0C<- seq(1,N),
> > =A0 =A0 =A0 =A0 =A0A + B + C =3D< =A0N,
> > =A0 =A0 =A0 =A0 =A0(A * A) + (B * B) =3D:=3D C * C].
>
> that's not recursive. that's a list comprehension.
Yes, it's a list comprehension. My question was, can you write a
Pythagorean triple function in Perl using recursion?
NOT my intent to start a language war, but simply a question that (for
some reason) I found interesting and perplexing, and thought I would
post it to c.l.p.m.
I understand recursion as solving a problem by calling either directly
or indirectly the original function with a smaller set of the original
data until it returns on some base case. Obviously, you can't have a
diminishing data set starting at 0 and increasing up a larger number,
but you CAN recurse starting at 0 until you get to a base case. Here
is a recursive implementation of a function seq() as might have been
used in the Erlang program.
#! perl
use strict;
use warnings;
my $n =3D $ARGV[0];
print "N is $n\n";
my @seq =3D ();
sub seq
{
my $n1 =3D shift;
if ($n =3D=3D $n1) {return @seq;}
else { push @seq, $n1; seq(++$n1); }
}
seq(0);
print "@seq\n";;
exit(0);
------------------------------
Date: Wed, 16 Mar 2011 06:53:22 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: recursive Pythagorian triples
Message-Id: <3935d38f-3800-419d-838c-6caee5738713@l14g2000pre.googlegroups.com>
On Mar 16, 7:01=A0am, Justin C <justin.1...@purestblue.com> wrote:
> What I don't understand is recursion in this context.
Neither do I, which was the point of the post!
CC.
------------------------------
Date: Wed, 16 Mar 2011 07:31:24 -0700 (PDT)
From: Ed <ednotover@gmail.com>
Subject: Re: recursive Pythagorian triples
Message-Id: <251e97fd-3f02-4747-a2e3-c50917eb282b@w9g2000prg.googlegroups.com>
On Mar 16, 2:13=A0am, George Mpouras
<nospam.gravital...@hotmail.com.nospam> wrote:
[ much snipped ]
> Did you find any missing triplet ?
The code does not produce, say, 9,12,15 (nor does it produce
12,9,15). See my other post about iterating over a multiplier (the k
value described in the wiki article).
Ed
------------------------------
Date: Wed, 16 Mar 2011 16:01:14 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: recursive Pythagorian triples
Message-Id: <slrnio1k5q.t8i.hjp-usenet2@hrunkner.hjp.at>
On 2011-03-16 13:53, ccc31807 <cartercc@gmail.com> wrote:
> On Mar 16, 7:01 am, Justin C <justin.1...@purestblue.com> wrote:
>> What I don't understand is recursion in this context.
>
> Neither do I, which was the point of the post!
"Neither do I" or "Neither did I"?
It is trivial to convert a loop into recursion. I think my first answer
to your posting illustrated that. If you still don't understand it, feel
free to ask (as a followup to that posting).
hp
------------------------------
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 3323
***************************************