[24616] in Perl-Users-Digest
Perl-Users Digest, Issue: 6792 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 11 18:05:39 2004
Date: Sun, 11 Jul 2004 15:05:09 -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 Sun, 11 Jul 2004 Volume: 10 Number: 6792
Today's topics:
Re: date problem <bob@dont.spam.me>
Re: date problem (Peter J. Acklam)
Re: date problem <gn20040711T220920@tt.oma.it.jyu.fi>
Re: date problem <opengeometry@yahoo.ca>
Re: date problem <noreply@gunnar.cc>
Re: LAMP - Program Design with Perl (Dieter)
Re: LAMP - Program Design with Perl (Anno Siegel)
Memory leak with Inline::C (Anno Siegel)
Re: Memory leak with Inline::C <1usa@llenroc.ude.invalid>
Re: Memory leak with Inline::C ctcgag@hotmail.com
Re: Memory leak with Inline::C <tassilo.von.parseval@rwth-aachen.de>
Re: Memory leak with Inline::C (Anno Siegel)
Re: Memory leak with Inline::C (Anno Siegel)
Re: Perl Regex Question: how to translate only the lead <krahnj@acm.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 11 Jul 2004 18:43:21 GMT
From: Bob <bob@dont.spam.me>
Subject: Re: date problem
Message-Id: <pan.2004.07.11.18.43.20.843535@dont.spam.me>
On Sun, 11 Jul 2004 17:21:08 +0200, Peter J. Acklam wrote:
> Bob <bob@dont.spam.me> wrote:
>
>> On Sun, 11 Jul 2004 16:21:38 +0200, Gabkin wrote:
>>
>> > Is there a quick and easy way of getting that extra degree of
>> > precision with 'date'?
>>
>> Precision? There will never be more than two digits in the seconds field
>> (00-60 -- yes, 60. See man date!).
>
> "Precision" is the number of digits relative to the decimal point. Higher
> precision means more digits after the decimal point, i.e., higher
> resolution. For instance, a precision of 3 would include milliseconds.
>
> Peter
Ahh ... In that case we need the first digit of nanoseconds:
set $(date +%Y%m%d%H%M%S%N)
echo ${1:0:15}
although that could result in a rounding error. Might want to get one
more digit and calculate the proper rounding (left as an exercise for the
reader!) (So is dealing with the value "60", admittedly rare.)
P.S. "Precision" does not imply relationship to a decimal point. It means
"number of significant digits". For example, saying there are a million
fish in the sea is less precise than saying there are 1,247,683 fish in
the sea. My initial reading was that there could never be more than two
significant digits when counting seconds in a minute.
------------------------------
Date: 11 Jul 2004 21:10:34 +0200
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: date problem
Message-Id: <vfguiclx.fsf@online.no>
Bob <bob@dont.spam.me> wrote:
> Peter J. Acklam wrote:
>
> > Bob <bob@dont.spam.me> wrote:
> >
> > "Precision" is the number of digits relative to the decimal
> > point. Higher precision means more digits after the decimal
> > point, i.e., higher resolution. For instance, a precision of
> > 3 would include milliseconds.
>
> Ahh ... In that case we need the first digit of nanoseconds:
>
> set $(date +%Y%m%d%H%M%S%N)
> echo ${1:0:15}
>
> although that could result in a rounding error.
Huh. I didn't know date has a %N. I see GNU date has, although I
don't have a Solaris box here to check if that too has %N.
> P.S. "Precision" does not imply relationship to a decimal
> point. It means "number of significant digits"
I was using the lingo from numerical analysis related to floating
point arithmetic. And there, the total number of significant
digits is called "accuracy", whereas "precision" is the number of
digits relative to the decimal point.
> For example, saying there are a million fish in the sea is less
> precise than saying there are 1,247,683 fish in the sea.
Right, which is "precision" as used in everyday language. And
that was probably what OP used too.
> My initial reading was that there could never be more than two
> significant digits when counting seconds in a minute.
That was mine too. :-)
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
------------------------------
Date: 11 Jul 2004 22:18:15 +0300
From: Tapani Tarvainen <gn20040711T220920@tt.oma.it.jyu.fi>
Subject: Re: date problem
Message-Id: <n6r7ri5p54.fsf@ukri.tt.it.jyu.fi>
Bob <bob@dont.spam.me> writes:
> Ahh ... In that case we need the first digit of nanoseconds:
>
> set $(date +%Y%m%d%H%M%S%N)
Interesting. In HP-UX date +%N gives emperor name (for Japanese
calendar), not nanoseconds... it doesn't seem to be defined
at all by POSIX. But it does seem to work with Gnu date.
> echo ${1:0:15}
That is also non-POSIX, it assumes bash or ksh93 or similar.
But with Gnu date you can simply use "%-1N" to get only the first
digit of nanoseconds (= deciseconds).
--
Tapani Tarvainen
------------------------------
Date: 11 Jul 2004 20:48:30 GMT
From: William Park <opengeometry@yahoo.ca>
Subject: Re: date problem
Message-Id: <2ldnctFbjo5hU2@uni-berlin.de>
In <comp.unix.shell> Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
> On 2004-07-11, Gabkin wrote:
> > I need to generate a date in the format YYYYMMDDHHMMSSS for a perl
> > program. (Note the _three_ digits allocated for Seconds, not the
> > usual _two_)
> >
> > date +%Y%m%d%H%M%S will give YYYYMMDDHHMMSS which is close but it
> > doesnt have that extra S at the end.
> >
> > I am using "date (sh-utils) 2.0.15" and "perl, v5.8.2" on Cygwin.
> >
> > Is there a quick and easy way of getting that extra degree of
> > precision with 'date'?
>
> date +%Y%m%d%H%M%03S
This will pad 0 on the left. So, 2 second becomes 002 instead of 02.
Usually, SSS means SS.s where 's' is 1/10 of second. In that case, just
append 0.
--
William Park, Open Geometry Consulting, <opengeometry@yahoo.ca>
Toronto, Ontario, Canada
------------------------------
Date: Sun, 11 Jul 2004 23:04:36 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: date problem
Message-Id: <2ldo6cFb9um5U1@uni-berlin.de>
Gabkin wrote:
> I need to generate a date in the format YYYYMMDDHHMMSSS for a perl
> program. (Note the _three_ digits allocated for Seconds, not the
> usual _two_)
sub timestamp {
require Time::HiRes;
my ($epoch, $micro) = Time::HiRes::gettimeofday();
my ($s, $mi, $h, $d, $mo, $y) = (localtime $epoch)[0..5];
sprintf '%d%02d%02d%02d%02d%02d%.0f',
$y+1900, $mo+1, $d, $h, $mi, $s, $micro/100000
}
print timestamp();
Outputs e.g.:
200407112303299
P.S.
http://groups.google.com/groups?selm=2lcs92Fbdp10U1%40uni-berlin.de
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 11 Jul 2004 12:26:58 -0700
From: affenkopf2004@yahoo.de (Dieter)
Subject: Re: LAMP - Program Design with Perl
Message-Id: <34dd0a89.0407111126.4c7e85de@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<ccrg0d$hlh$1@mamenchi.zrz.TU-Berlin.DE>...
Yes, I think this is going to the right direction.
The whole thing could be wrapped by "foreach" (see below).
It's not so easy to explain, but my main problem is
that I have to dynamically generate Meta-Information.
Since I don't know what kind of Information the user requests,
it has to be stored somewhere that the e.g. second column returned
from the database is 'color' and not 'size' or 'shape' .
Maybe I do it that way: slurp all parameters from the user
into a hash and then go through all possible parameters
with "foreach" and "if defined".
Maybe the trick is to name the parameters in the HTML-form
exactly the same as they are named in the database and store
the database information in an hash of hashes.
Thanks, Dieter
> Instead of writing
>
> if ( $thing eq 'apple' ) {
> # code to deal with apple
> } elsif ( $thing eq 'car' ) {
> # code to deal with car
> } elsif ( ... ) {
>
> you can construct a hash
>
> my %action = (
> apple => sub {
> # code to deal with apple
> },
> car => sub {
> # code to deal with car
> },
> # ...
> );
>
> and replace the entire if/elsif construct with
>
> $action{ $thing}->();
------------------------------
Date: 11 Jul 2004 20:14:19 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: LAMP - Program Design with Perl
Message-Id: <ccs72r$17i$1@mamenchi.zrz.TU-Berlin.DE>
Dieter <affenkopf2004@yahoo.de> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> news:<ccrg0d$hlh$1@mamenchi.zrz.TU-Berlin.DE>...
>
> Yes, I think this is going to the right direction.
What is? Please provide context. I have moved the rest of your reply
to the bottom. Please follow the preferred posting style.
> > Instead of writing
> >
> > if ( $thing eq 'apple' ) {
> > # code to deal with apple
> > } elsif ( $thing eq 'car' ) {
> > # code to deal with car
> > } elsif ( ... ) {
> >
> > you can construct a hash
> >
> > my %action = (
> > apple => sub {
> > # code to deal with apple
> > },
> > car => sub {
> > # code to deal with car
> > },
> > # ...
> > );
> >
> > and replace the entire if/elsif construct with
> >
> > $action{ $thing}->();
> The whole thing could be wrapped by "foreach" (see below).
>
> It's not so easy to explain, but my main problem is
> that I have to dynamically generate Meta-Information.
If you find it hard to explain, you have not fully understood your
problem yet.
> Since I don't know what kind of Information the user requests,
> it has to be stored somewhere that the e.g. second column returned
> from the database is 'color' and not 'size' or 'shape' .
Does that mean that the second column of the database stores all
three types of data, and you must know from somewhere else what
it is?
Or are we talking multiple databases, each a key-value mapping
as in tied hashes? It's hard to comment unless you define your
terms more clearly. Or something else?
> Maybe I do it that way: slurp all parameters from the user
> into a hash and then go through all possible parameters
> with "foreach" and "if defined".
No comment on that either, unless you say what you mean by "parameter"
> Maybe the trick is to name the parameters in the HTML-form
> exactly the same as they are named in the database and store
> the database information in an hash of hashes.
That sounds distinctly like a bad idea. Don't tie data together that
underlie independent constraints. (Column-) names in a data base have
one syntax, parameter names in HTML-forms have another. They have
independent life cycles and change for different reasons. Don't force
them together. If those names are user-visible (still not sure what
exactly we're talking about), that's a further no-no.
Instead, it would be a job for a hash to associate user-chooseable
strings with the info needed to access the data base. Another hash
(or the same one) could store the info needed to display the data.
It's hard to be more specific at this point.
Anno
------------------------------
Date: 11 Jul 2004 19:28:54 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Memory leak with Inline::C
Message-Id: <ccs4dm$sr2$1@mamenchi.zrz.TU-Berlin.DE>
I'm seeing a memory leak with the Inline code below. The sub by_inline()
returns a varying number of scalars, which is probably the crux of the
matter.
The code works as expected (returning the exponents of 2 used in the
binary representation of the argument), but the loop leaks. It leaks
just the same when by_inline() is called in void context.
I don't see anything obviously wrong with the code, in particular the
newly created SVs are carefully mortalized, but I'd like a second opinion.
I'd also be grateful if one or the other could find the time to run
the code and report back. For me, the process grows to 500+ MB before
the loop runs out (I kill it when swapping becomes audible).
Conditions here:
Darwin 7.4.0, Perl 5.8.4, Inline 0.44, gcc 3.3
Update:
It also leaks on a Linux with Perl 5.8.1, same Inline, unknown gcc.
Anno
#!/usr/local/bin/perl
use strict; use warnings; $| = 1;
use Vi::QuickFix;
my @res = by_inline( int rand 2 ** 32) for 1 .. 100_000;
use Inline C => <<EOC;
void by_inline( int x) {
int i;
Inline_Stack_Vars;
Inline_Stack_Reset;
i = 0;
while ( x ) {
if ( x & 1 ) {
Inline_Stack_Push( sv_2mortal( newSViv( i)));
}
x >>= 1;
i ++;
}
Inline_Stack_Done;
}
EOC
__END__
------------------------------
Date: 11 Jul 2004 19:40:27 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Memory leak with Inline::C
Message-Id: <Xns95239F706838Aasu1cornelledu@132.236.56.8>
On 11 Jul 2004, you wrote in comp.lang.perl.misc:
Anno:
I haven't had a chance to take a serious look (I am taking baby steps
into finding out about Perl internals), but
> I'd also be grateful if one or the other could find the time to run
> the code and report back. For me, the process grows to 500+ MB before
> the loop runs out (I kill it when swapping becomes audible).
>
> Conditions here:
> Darwin 7.4.0, Perl 5.8.4, Inline 0.44, gcc 3.3
>
> Update:
> It also leaks on a Linux with Perl 5.8.1, same Inline, unknown gcc.
FBSD 5.2, Perl 5.8.4, Inline 0.44, gcc 3.3
script gets killed by OS rather quickly. Didn't try it on my Win XP.
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: 11 Jul 2004 20:13:35 GMT
From: ctcgag@hotmail.com
Subject: Re: Memory leak with Inline::C
Message-Id: <20040711161335.703$DX@newsreader.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> I'm seeing a memory leak with the Inline code below. The sub by_inline()
> returns a varying number of scalars, which is probably the crux of the
> matter.
...
The problem is not with Inline::C, it is with plain C. Certain arguments
to the function throw your C code into an infinite loop. I suspect it is
due to the fact that not all numbers up to 2**32 fit into a signed int.
I changed the signature line to:
void by_inline( unsigned int x) {
And the problem went away.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Sun, 11 Jul 2004 22:22:59 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: Memory leak with Inline::C
Message-Id: <2ldlt5FbretpU1@uni-berlin.de>
Also sprach Anno Siegel:
> I'm seeing a memory leak with the Inline code below. The sub by_inline()
> returns a varying number of scalars, which is probably the crux of the
> matter.
Actually, the problem is that your program may produce infinite loops.
> The code works as expected (returning the exponents of 2 used in the
> binary representation of the argument), but the loop leaks. It leaks
> just the same when by_inline() is called in void context.
>
> I don't see anything obviously wrong with the code, in particular the
> newly created SVs are carefully mortalized, but I'd like a second opinion.
>
> I'd also be grateful if one or the other could find the time to run
> the code and report back. For me, the process grows to 500+ MB before
> the loop runs out (I kill it when swapping becomes audible).
>
> Conditions here:
> Darwin 7.4.0, Perl 5.8.4, Inline 0.44, gcc 3.3
>
> Update:
> It also leaks on a Linux with Perl 5.8.1, same Inline, unknown gcc.
>
> Anno
>
> #!/usr/local/bin/perl
> use strict; use warnings; $| = 1;
> use Vi::QuickFix;
>
> my @res = by_inline( int rand 2 ** 32) for 1 .. 100_000;
A value in the above range might not fit into a signed 32bit integer. In
this case it gets wrapped around and 'x' in the below C function ends up
being negative. So 'x' will eventually become -1 and never turn zero.
And there you have your infinite while-loop.
> use Inline C => <<EOC;
> void by_inline( int x) {
> int i;
> Inline_Stack_Vars;
> Inline_Stack_Reset;
> i = 0;
> while ( x ) {
> if ( x & 1 ) {
> Inline_Stack_Push( sv_2mortal( newSViv( i)));
> }
> x >>= 1;
> i ++;
> }
> Inline_Stack_Done;
> }
> EOC
> __END__
One fix would be to increase the range of your numbers:
void by_inline(double X) {
long long x = X;
...
}
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 11 Jul 2004 20:43:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Memory leak with Inline::C
Message-Id: <ccs8qe$264$1@mamenchi.zrz.TU-Berlin.DE>
<ctcgag@hotmail.com> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> > I'm seeing a memory leak with the Inline code below. The sub by_inline()
> > returns a varying number of scalars, which is probably the crux of the
> > matter.
>
> ...
>
> The problem is not with Inline::C, it is with plain C. Certain arguments
> to the function throw your C code into an infinite loop. I suspect it is
> due to the fact that not all numbers up to 2**32 fit into a signed int.
Yes. C's >> is an arithmetic shift, and pulls in one-bits with negative
integers. (Perl's >> appears to be a logical shift.) So a single
call got stuck and kept allocating. That would "leak" some, yes.
> I changed the signature line to:
> void by_inline( unsigned int x) {
>
> And the problem went away.
Thank you, thank you!
Boy did I misread my results. Apologies to Inline, Ingy, and anyone
else concerned. They are absolutely innocent of leaking.
Anno
------------------------------
Date: 11 Jul 2004 20:51:57 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Memory leak with Inline::C
Message-Id: <ccs99d$264$2@mamenchi.zrz.TU-Berlin.DE>
Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote in comp.lang.perl.misc:
> Also sprach Anno Siegel:
>
> > I'm seeing a memory leak with the Inline code below. The sub by_inline()
> > returns a varying number of scalars, which is probably the crux of the
> > matter.
>
> Actually, the problem is that your program may produce infinite loops.
Indeed. I replied to Xho, who made the same observation. Thanks
again.
Anno
------------------------------
Date: Sun, 11 Jul 2004 18:06:19 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Perl Regex Question: how to translate only the leading letters of a line
Message-Id: <40F18198.C396A696@acm.org>
Yu wrote:
>
> I wonder if there is an elegant way of converting
> number 1-9 into letter A-I for the LEADING letter
> of a line. For example:
>
> Input:
> 1 xxxx1234....
>
> Ouput:
> A xxxx1234....
>
> The tr operator does not take the special position
> character such as '^' and '$', so it would operate
> on every match in the input line. Any input will
> greatly appreciated.
Here is one way to do it:
s/^([1-9])(?= xxxx1234)/qw(A B C D E F G H I)[$1-1]/e;
John
--
use Perl;
program
fulfillment
------------------------------
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 6792
***************************************