[29955] in Perl-Users-Digest
Perl-Users Digest, Issue: 1198 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 15 14:09:42 2008
Date: Tue, 15 Jan 2008 11:09:07 -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 Tue, 15 Jan 2008 Volume: 11 Number: 1198
Today's topics:
checking file age <beefstu350@hotmail.com>
Re: checking file age <mritty@gmail.com>
Re: checking file age <rwxrxrx@gmail.com>
Re: checking file age <beefstu350@hotmail.com>
Re: checking file age <jurgenex@hotmail.com>
Re: checking file age <beefstu350@hotmail.com>
Re: Converting milliseconds to seconds <hjp-usenet2@hjp.at>
Re: Converting milliseconds to seconds <simon.chao@fmr.com>
Re: Converting milliseconds to seconds <abigail@abigail.be>
Re: Converting milliseconds to seconds <simon.chao@fmr.com>
Re: Converting milliseconds to seconds <joost@zeekat.nl>
Re: Converting milliseconds to seconds <hjp-usenet2@hjp.at>
Re: Converting milliseconds to seconds <jimsgibson@gmail.com>
Re: Converting milliseconds to seconds <joost@zeekat.nl>
Re: Cpan problems <john@castleamber.com>
How to detect text charset (UTF-8 or Latin-1) <tarmstrong@gmail.com>
Re: How to detect text charset (UTF-8 or Latin-1) <yankeeinexile@gmail.com>
Re: How to detect text charset (UTF-8 or Latin-1) <smallpond@juno.com>
mod_perl ignoring changed to $ENV{{PATH}? <bwooster47@gmail.com>
Re: Referencing modules nested in a directory structure <pue@gmx.net>
Re: Shebang line management <jurgenex@hotmail.com>
Re: USEFUL perl SCRIPT: NTP verifier <hjp-usenet2@hjp.at>
Re: USEFUL perl SCRIPT: NTP verifier <ignoramus25819@NOSPAM.25819.invalid>
Re: USEFUL perl SCRIPT: NTP verifier <john@castleamber.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 15 Jan 2008 07:46:00 -0800 (PST)
From: Stu <beefstu350@hotmail.com>
Subject: checking file age
Message-Id: <d2ca27ef-9b7e-4143-8ab0-302688429a2c@v29g2000hsf.googlegroups.com>
Can somebody provide me with a perl funcion that accepts
(full path of file, number of minutes, and operation) and checks the
last access time of a file.
For example, if I pass the following:
c:/temp/testfile 5 GT
The function will check the last access time of the file c:/temp/
testfile and see if it is greater than 5 minutes old.
If I pass c:/temp/testfile 6 LE
The function will check the last access time of the file c:/temp/
testfile and see if it is less than or equal to 6 minutes old.
If the anwer is yes I want to return 1 for TRUE else return 0 for
false.
Thanks in advance for all that answer this post
I
------------------------------
Date: Tue, 15 Jan 2008 07:50:50 -0800 (PST)
From: Paul Lalli <mritty@gmail.com>
Subject: Re: checking file age
Message-Id: <91e987ed-8075-457e-bfc2-e04d5434cd0d@c23g2000hsa.googlegroups.com>
On Jan 15, 10:46=A0am, Stu <beefstu...@hotmail.com> wrote:
> Can somebody provide me with a perl funcion that accepts
> (full path of file, number of minutes, and operation) and checks
> the last access time of a file.
>
> For example, if I pass the following:
>
> c:/temp/testfile =A0 =A05 =A0 =A0 GT
>
> The function will check the last access time of the file c:/temp/
> testfile and see if it is greater than 5 minutes old.
>
> If I pass c:/temp/testfile =A0 =A06 =A0 =A0 LE
>
> The function will check the last access time of the file c:/temp/
> testfile and see if it is less than or equal to 6 minutes old.
>
> If the anwer is yes I want to return 1 for TRUE else return 0 for
> false.
>
> Thanks in advance for all that answer this post
What have you done so far? What part is causing you problems? Please
post a short but complete script that demonstrates the issue you're
having.
To find the last access time of a file in seconds, you use the -A
operator:
my $secs =3D -A $file;
To find minutes from seconds, you divide by 60
my $minutes =3D $secs / 60;
To compare a number to a given value, you use one of the numeric
comparison operators: <, >, <=3D, >=3D, =3D=3D, !=3D
To learn how to write a subroutine, you read `perldoc perlsub` by
typing those two words in a command window.
If you make an attempt to solve your own problem, people here will be
very willing to help you and show you where you might be going wrong.
Paul Lalli
------------------------------
Date: Wed, 16 Jan 2008 00:48:51 +0800
From: "Scott.Jo" <rwxrxrx@gmail.com>
Subject: Re: checking file age
Message-Id: <fmisva$ng9$1@news.cn99.com>
Stu 写道:
> Can somebody provide me with a perl funcion that accepts
> (full path of file, number of minutes, and operation) and checks the
> last access time of a file.
>
> For example, if I pass the following:
>
> c:/temp/testfile 5 GT
>
> The function will check the last access time of the file c:/temp/
> testfile and see if it is greater than 5 minutes old.
>
> If I pass c:/temp/testfile 6 LE
>
> The function will check the last access time of the file c:/temp/
> testfile and see if it is less than or equal to 6 minutes old.
>
> If the anwer is yes I want to return 1 for TRUE else return 0 for
> false.
>
> Thanks in advance for all that answer this post
>
>
>
>
>
>
> I
>
It's your homework?
------------------------------
Date: Tue, 15 Jan 2008 08:57:35 -0800 (PST)
From: Stu <beefstu350@hotmail.com>
Subject: Re: checking file age
Message-Id: <df25a26a-82de-43ae-b48c-17cd780fc9ca@k39g2000hsf.googlegroups.com>
On Jan 15, 11:48 am, "Scott.Jo" <rwxr...@gmail.com> wrote:
> Stu $B<LF;(B:
>
>
>
> > Can somebody provide me with a perl funcion that accepts
> > (full path of file, number of minutes, and operation) and checks the
> > last access time of a file.
>
> > For example, if I pass the following:
>
> > c:/temp/testfile 5 GT
>
> > The function will check the last access time of the file c:/temp/
> > testfile and see if it is greater than 5 minutes old.
>
> > If I pass c:/temp/testfile 6 LE
>
> > The function will check the last access time of the file c:/temp/
> > testfile and see if it is less than or equal to 6 minutes old.
>
> > If the anwer is yes I want to return 1 for TRUE else return 0 for
> > false.
>
> > Thanks in advance for all that answer this post
>
> > I
>
> It's your homework?- Hide quoted text -
>
> - Show quoted text -
No it is not, just needed help with the -A for access time. All done
thanks eveyr
------------------------------
Date: Tue, 15 Jan 2008 18:25:12 GMT
From: Jrgen Exner <jurgenex@hotmail.com>
Subject: Re: checking file age
Message-Id: <0iupo3h2k196frjchendltm7brdovmt6mb@4ax.com>
Stu <beefstu350@hotmail.com> wrote:
>Can somebody provide me with a perl funcion that accepts
>(full path of file, number of minutes, and operation) and checks the
>last access time of a file.
See
perldoc -f -X (you are looking for -A)
perldoc perlop (you are looking for > and <=)
jue
------------------------------
Date: Tue, 15 Jan 2008 10:35:06 -0800 (PST)
From: Stu <beefstu350@hotmail.com>
Subject: Re: checking file age
Message-Id: <cff60d82-a4fb-46c3-8949-b4de680c2e91@v29g2000hsf.googlegroups.com>
On Jan 15, 10:50=A0am, Paul Lalli <mri...@gmail.com> wrote:
> On Jan 15, 10:46=A0am, Stu <beefstu...@hotmail.com> wrote:
>
>
>
>
>
> > Can somebody provide me with a perl funcion that accepts
> > (full path of file, number of minutes, and operation) and checks
> > the last access time of a file.
>
> > For example, if I pass the following:
>
> > c:/temp/testfile =A0 =A05 =A0 =A0 GT
>
> > The function will check the last access time of the file c:/temp/
> > testfile and see if it is greater than 5 minutes old.
>
> > If I pass c:/temp/testfile =A0 =A06 =A0 =A0 LE
>
> > The function will check the last access time of the file c:/temp/
> > testfile and see if it is less than or equal to 6 minutes old.
>
> > If the anwer is yes I want to return 1 for TRUE else return 0 for
> > false.
>
> > Thanks in advance for all that answer this post
>
> What have you done so far? =A0What part is causing you problems? =A0Please=
> post a short but complete script that demonstrates the issue you're
> having.
>
> To find the last access time of a file in seconds, you use the -A
> operator:
> my $secs =3D -A $file;
>
> To find minutes from seconds, you divide by 60
> my $minutes =3D $secs / 60;
>
> To compare a number to a given value, you use one of the numeric
> comparison operators: <, >, <=3D, >=3D, =3D=3D, !=3D
>
> To learn how to write a subroutine, you read `perldoc perlsub` by
> typing those two words in a command window.
>
> If you make an attempt to solve your own problem, people here will be
> very willing to help you and show you where you might be going wrong.
>
> Paul Lalli- Hide quoted text -
>
> - Show quoted text -
Paul,
Thanks for your help but I think -A returns the value in days and not
seconds. (see below).
I am going to take the current time in secs and subtract the stat time
and that should do it for me.
File test Meaning
-r File is readable by effective uid/gid
-w File is writable by effective uid/gid.
-x File is executable by effective uid/gid.
-o File is owned by effective uid.
-R File is readable by real uid/gid.
-W File is writable by real uid/gid.
-X File is executable by real uid/gid.
-O File is owned by real uid.
-e File exists.
-z File has zero size (is empty).
-s File has nonzero size (returns size in bytes).
-f File is a plain file.
-d File is a directory.
-l File is a symbolic link.
-p File is a named pipe (FIFO), or Filehandle is a pipe.
-S File is a socket.
-b File is a block special file.
-c File is a character special file.
-t Filehandle is opened to a tty
-u File has setuid bit set.
-g File has setgid bit set.
-k File has sticky bit set.
-T File is an ASCII text file (heuristic guess).
-B File is a "binary" file (opposite of -T).
-M Script start time minus file modification time, in days.
-A Same for access time.
-C Same for inode change time (Unix, may differ for other platforms)
------------------------------
Date: Tue, 15 Jan 2008 15:34:31 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Converting milliseconds to seconds
Message-Id: <slrnfoph3u.mma.hjp-usenet2@hrunkner.hjp.at>
On 2008-01-13 02:32, Jrgen Exner <jurgenex@hotmail.com> wrote:
> Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
>>[A complimentary Cc of this posting was sent to
>>Jrgen Exner
>
> Please don't do that. I happen to read the NGs in which I am posting.
>
>><jurgenex@hotmail.com>], who wrote in article <ik3go3pgkcrol2diigag1hl2prkke0ktt7@4ax.com>:
[ perldoc -f int: You should not use this function for rounding]
>>> >This is just a reflection of a sorry state of Perl documentation.
>>> >There is NO OTHER WAY to round-to-0 but to use int().
>>>
>>> Your statement is non sequitur. int() does not an never was supposed to
>>> round a number. If you expect int() to round a number then you are mistaken
>>> about the semantic of this function.
>>
>>I assure you that int() does nothing else but rounding-to-0.
>
> As I said: you are greatly mistaken about the intended semantic of int().
> You may want to read the documentation for clarification.
Saying that to Ilya is a bit humorous.
Ilya is completely correct that int does round to 0 (repeat: round to
zero - not round to nearest!). And that is the intended semantics -
perldoc -f int says so: "Returns the integer portion of EXPR".
But I think Ilya is a barking up the wrong tree here:
>>> >This is just a reflection of a sorry state of Perl documentation.
>>> >There is NO OTHER WAY to round-to-0 but to use int().
Of course there is no other way to round-to-0, but the manual is talking
about "rounding" here: And "rounding" without any qualifiers usually
means "round to nearest", not "round to 0".
The entry is still confusing: The hint to use sprintf instead is ok, but
in what way are floor and ceil supposed to be better than int? And the
caveat about decimal/binary confusions isn't really a reason for "don't
use int for rounding" - any rounding method has the same problem.
hp
------------------------------
Date: Tue, 15 Jan 2008 06:51:52 -0800 (PST)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: Converting milliseconds to seconds
Message-Id: <95ae1f01-ec95-4b90-805b-08818f6441a2@v4g2000hsf.googlegroups.com>
On Jan 15, 9:34=A0am, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
> On 2008-01-13 02:32, J=FCrgen Exner <jurge...@hotmail.com> wrote:
>
> > Ilya Zakharevich <nospam-ab...@ilyaz.org> wrote:
> >>[A complimentary Cc of this posting was sent to
> >>J=FCrgen Exner
>
> > Please don't do that. I happen to read the NGs in which I am posting.
>
> >><jurge...@hotmail.com>], who wrote in article <ik3go3pgkcrol2diigag1hl2p=
rkke0k...@4ax.com>:
>
> [ perldoc -f int: You should not use this function for rounding]
>
> >>> >This is just a reflection of a sorry state of Perl documentation.
> >>> >There is NO OTHER WAY to round-to-0 but to use int(). =A0
>
> >>> Your statement is non sequitur. int() does not an never was supposed t=
o
> >>> round a number. If you expect int() to round a number then you are mis=
taken
> >>> about the semantic of this function.
>
> >>I assure you that int() does nothing else but rounding-to-0.
>
> > As I said: you are greatly mistaken about the intended semantic of int()=
.
> > You may want to read the documentation for clarification.
>
> Saying that to Ilya is a bit humorous.
>
> Ilya is completely correct that int does round to 0 (repeat: round to
> zero - not round to nearest!). And that is the intended semantics -
> perldoc -f int says so: "Returns the integer portion of EXPR".
>
> But I think Ilya is a barking up the wrong tree here:
>
> >>> >This is just a reflection of a sorry state of Perl documentation.
> >>> >There is NO OTHER WAY to round-to-0 but to use int(). =A0
>
> Of course there is no other way to round-to-0, but the manual is talking
> about "rounding" here: And "rounding" without any qualifiers usually
> means "round to nearest", not "round to 0".
>
> The entry is still confusing: The hint to use sprintf instead is ok, but
> in what way are floor and ceil supposed to be better than int? And the
> caveat about decimal/binary confusions isn't really a reason for "don't
> use int for rounding" - any rounding method has the same problem.
>
Ok, so this is a stupid question. What's wrong with the following?
sub round {
my $number =3D shift;
return int($number + .5);
}
------------------------------
Date: 15 Jan 2008 14:56:17 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Converting milliseconds to seconds
Message-Id: <slrnfopicg.e71.abigail@alexandra.abigail.be>
_
Peter J. Holzer (hjp-usenet2@hjp.at) wrote on VCCL September MCMXCIII in
<URL:news:slrnfoph3u.mma.hjp-usenet2@hrunkner.hjp.at>:
}}
}} Of course there is no other way to round-to-0, but the manual is talking
}} about "rounding" here: And "rounding" without any qualifiers usually
}} means "round to nearest", not "round to 0".
}}
}} The entry is still confusing: The hint to use sprintf instead is ok, but
}} in what way are floor and ceil supposed to be better than int? And the
}} caveat about decimal/binary confusions isn't really a reason for "don't
}} use int for rounding" - any rounding method has the same problem.
Neither floor, nor ceil does the same as int.
int: round to 0.
floor: round to -inf.
ceil: round to +inf.
sprintf: round to nearest.
+-------------------------+
| $x |
+-----+------+-----+------+
| 1.2 | -1.2 | 1.7 | -1.7 |
+------------------+-----+------+-----+------+
| int $x | 1 | -1 | 1 | -1 |
+------------------+-----+------+-----+------+
| floor $x | 1 | -2 | 1 | -2 |
+------------------+-----+------+-----+------+
| ceil $x | 2 | -1 | 2 | -1 |
+------------------+-----+------+-----+------+
| sprintf "%d", $x | 1 | -1 | 2 | -2 |
+------------------+-----+------+-----+------+
Abigail
--
$_ = "\nrekcaH lreP rehtona tsuJ"; my $chop; $chop = sub {print chop; $chop};
$chop -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
-> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
------------------------------
Date: Tue, 15 Jan 2008 07:06:34 -0800 (PST)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: Converting milliseconds to seconds
Message-Id: <82c8c1fe-e003-442b-afef-9d8789924a05@e4g2000hsg.googlegroups.com>
On Jan 15, 9:51=A0am, nolo contendere <simon.c...@fmr.com> wrote:
> On Jan 15, 9:34=A0am, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
>
>
>
> > On 2008-01-13 02:32, J=FCrgen Exner <jurge...@hotmail.com> wrote:
>
> > > Ilya Zakharevich <nospam-ab...@ilyaz.org> wrote:
> > >>[A complimentary Cc of this posting was sent to
> > >>J=FCrgen Exner
>
> > > Please don't do that. I happen to read the NGs in which I am posting.
>
> > >><jurge...@hotmail.com>], who wrote in article <ik3go3pgkcrol2diigag1hl=
2prkke0k...@4ax.com>:
>
> > [ perldoc -f int: You should not use this function for rounding]
>
> > >>> >This is just a reflection of a sorry state of Perl documentation.
> > >>> >There is NO OTHER WAY to round-to-0 but to use int(). =A0
>
> > >>> Your statement is non sequitur. int() does not an never was supposed=
to
> > >>> round a number. If you expect int() to round a number then you are m=
istaken
> > >>> about the semantic of this function.
>
> > >>I assure you that int() does nothing else but rounding-to-0.
>
> > > As I said: you are greatly mistaken about the intended semantic of int=
().
> > > You may want to read the documentation for clarification.
>
> > Saying that to Ilya is a bit humorous.
>
> > Ilya is completely correct that int does round to 0 (repeat: round to
> > zero - not round to nearest!). And that is the intended semantics -
> > perldoc -f int says so: "Returns the integer portion of EXPR".
>
> > But I think Ilya is a barking up the wrong tree here:
>
> > >>> >This is just a reflection of a sorry state of Perl documentation.
> > >>> >There is NO OTHER WAY to round-to-0 but to use int(). =A0
>
> > Of course there is no other way to round-to-0, but the manual is talking=
> > about "rounding" here: And "rounding" without any qualifiers usually
> > means "round to nearest", not "round to 0".
>
> > The entry is still confusing: The hint to use sprintf instead is ok, but=
> > in what way are floor and ceil supposed to be better than int? And the
> > caveat about decimal/binary confusions isn't really a reason for "don't
> > use int for rounding" - any rounding method has the same problem.
>
> Ok, so this is a stupid question. What's wrong with the following?
>
> sub round {
> =A0 =A0 my $number =3D shift;
> =A0 =A0 return int($number + .5);
>
> }
>
>
Well, for positive numbers, I mean.
------------------------------
Date: Tue, 15 Jan 2008 17:36:17 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: Converting milliseconds to seconds
Message-Id: <87tzlff3lq.fsf@zeekat.nl>
nolo contendere <simon.chao@fmr.com> writes:
> On Jan 15, 9:51 am, nolo contendere <simon.c...@fmr.com> wrote:
>> Ok, so this is a stupid question. What's wrong with the following?
>>
>> sub round {
>> my $number = shift;
>> return int($number + .5);
>>
>> }
>>
>>
>
> Well, for positive numbers, I mean.
It does a naive round to nearest: it rounds x + 0.5 to x+1 for *all
integers* x. In other words, it's biased: round(0) + round(0.5) +
round(1) + round(1.5) == 4. while you would really rather want it to be
2. That sort of bias can really affect your statistical or financial
calculations.
Generally this is "solved" by rounding to the nearest even number in
the (int+0.5) case. Which is what sprintf does on my system. Note that
this is only really a working strategy when the numbers you're rounding
have a reasonable range (i.e. it's still biased when your numbers are
in range 0 .. 1 for example).
See:
http://en.wikipedia.org/wiki/Banker%27s_rounding#Round-to-even_method
Joost.
------------------------------
Date: Tue, 15 Jan 2008 18:51:40 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Converting milliseconds to seconds
Message-Id: <slrnfopslc.mma.hjp-usenet2@hrunkner.hjp.at>
On 2008-01-15 14:56, Abigail <abigail@abigail.be> wrote:
> Peter J. Holzer (hjp-usenet2@hjp.at) wrote on VCCL September MCMXCIII in
><URL:news:slrnfoph3u.mma.hjp-usenet2@hrunkner.hjp.at>:
> }}
> }} Of course there is no other way to round-to-0, but the manual is talking
> }} about "rounding" here: And "rounding" without any qualifiers usually
> }} means "round to nearest", not "round to 0".
> }}
> }} The entry is still confusing: The hint to use sprintf instead is ok, but
> }} in what way are floor and ceil supposed to be better than int? And the
> }} caveat about decimal/binary confusions isn't really a reason for "don't
> }} use int for rounding" - any rounding method has the same problem.
>
>
> Neither floor, nor ceil does the same as int.
True. But what does that have to do with anything I wrote?
hp
------------------------------
Date: Tue, 15 Jan 2008 10:16:47 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Converting milliseconds to seconds
Message-Id: <150120081016474714%jimsgibson@gmail.com>
In article <slrnfopicg.e71.abigail@alexandra.abigail.be>, Abigail
<abigail@abigail.be> wrote:
> _
> Peter J. Holzer (hjp-usenet2@hjp.at) wrote on VCCL September MCMXCIII in
> <URL:news:slrnfoph3u.mma.hjp-usenet2@hrunkner.hjp.at>:
> }}
> }} Of course there is no other way to round-to-0, but the manual is talking
> }} about "rounding" here: And "rounding" without any qualifiers usually
> }} means "round to nearest", not "round to 0".
> }}
> }} The entry is still confusing: The hint to use sprintf instead is ok, but
> }} in what way are floor and ceil supposed to be better than int? And the
> }} caveat about decimal/binary confusions isn't really a reason for "don't
> }} use int for rounding" - any rounding method has the same problem.
>
>
> Neither floor, nor ceil does the same as int.
>
>
> int: round to 0.
> floor: round to -inf.
> ceil: round to +inf.
> sprintf: round to nearest.
What would be a good round() function that "rounds-to-nearest-even"?
Would using sprintf in this function slow it down? Is there any chance
such a function could be included as a built-in function in a future
Perl?
Inquiring (but too lazy to do the work themselves) minds want to know.
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: Tue, 15 Jan 2008 19:38:26 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: Converting milliseconds to seconds
Message-Id: <87k5mbexy5.fsf@zeekat.nl>
Jim Gibson <jimsgibson@gmail.com> writes:
> In article <slrnfopicg.e71.abigail@alexandra.abigail.be>, Abigail
> <abigail@abigail.be> wrote:
>
>> _
>> Peter J. Holzer (hjp-usenet2@hjp.at) wrote on VCCL September MCMXCIII in
>> <URL:news:slrnfoph3u.mma.hjp-usenet2@hrunkner.hjp.at>:
>> }}
>> }} Of course there is no other way to round-to-0, but the manual is talking
>> }} about "rounding" here: And "rounding" without any qualifiers usually
>> }} means "round to nearest", not "round to 0".
>> }}
>> }} The entry is still confusing: The hint to use sprintf instead is ok, but
>> }} in what way are floor and ceil supposed to be better than int? And the
>> }} caveat about decimal/binary confusions isn't really a reason for "don't
>> }} use int for rounding" - any rounding method has the same problem.
>>
>>
>> Neither floor, nor ceil does the same as int.
>>
>>
>> int: round to 0.
>> floor: round to -inf.
>> ceil: round to +inf.
>> sprintf: round to nearest.
>
>
> What would be a good round() function that "rounds-to-nearest-even"?
sprintf would work, but I'm not 100% sure it rounds to even on every
platform (it uses C's sprintf()). It works on my debian/x86 system though.
> Would using sprintf in this function slow it down?
Probably, but sprintf is more generic than a plain round anyway, since
it rounds to arbitrary decimal positions, and you can't use floats for
that so you'd have to use strings (since perl doesn't have native
rational numbers).
> Is there any chance
> such a function could be included as a built-in function in a future
> Perl?
Haven't heard of any plans (but that doesn't mean much). I'm still kind
of surprised that perl doesn't have round/floor/ceil in the base
language, but I suspect adding them now (before perl 6) would clash with
existing code.
Math::Round is on CPAN though :)
Joost.
------------------------------
Date: 15 Jan 2008 15:33:59 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Cpan problems
Message-Id: <Xns9A2661508B4A3castleamber@130.133.1.4>
Peter Makholm <peter@makholm.net> wrote:
> John Bokma <john@castleamber.com> writes:
>
>> It doesn't use CPAN, it requires that the module(s) you want are
>> available as a package apt/synaptic can handle. (for Fedora there is
>> software to make packages via CPAN)
>>
>> Ubuntu installs some Perl modules via apt AFAIK. If you update those
>> via CPAN, I can imagine stuff goes out of sync. And vice versa of
>> course.
>
> Most of the times it works just fine.
Which is not enough for me. Like I already wrote, I prefer a central
upgrade system anyway.
--
John
http://johnbokma.com/mexit/
------------------------------
Date: Tue, 15 Jan 2008 08:59:31 -0800 (PST)
From: Thomas Armstrong <tarmstrong@gmail.com>
Subject: How to detect text charset (UTF-8 or Latin-1)
Message-Id: <3585532f-f26b-42a7-ae1e-a3b44fb8edb5@q39g2000hsf.googlegroups.com>
Hi.
I'm creating a Perl script extracting text from a webpage using LWP,
and want to check if text is UTF-8 or Latin-1 encoded?
Is there any known function? I don't know if "use utf8;" is enough
Thank you very much in advance.
------------------------------
Date: 15 Jan 2008 11:22:09 -0600
From: Lawrence Statton <yankeeinexile@gmail.com>
Subject: Re: How to detect text charset (UTF-8 or Latin-1)
Message-Id: <87d4s3j96m.fsf@hummer.cluon.com>
Thomas Armstrong <tarmstrong@gmail.com> writes:
> Hi.
>
> I'm creating a Perl script extracting text from a webpage using LWP,
> and want to check if text is UTF-8 or Latin-1 encoded?
Considering that each and every series of UTF-8 octets is also a valid
(if nonsensical) series of Latin-1 octets, you are asking a question
that cannot be solved rigorously.
However, there are series of valid Latin-1 octets that are NOT
UTF-8, so that can be used as a heuristic guide.
Finally, you can devise a heuristic to give a confidence level that a
given series of octets is LIKELY to be UTF-8 or Latin-1 even in the
cases where they are valid in both codings.
The sad news is, I wrote one that works wonders, but the code is
encumbered.
--
Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer software consists of only two components: ones and
zeros, in roughly equal proportions. All that is required is to
place them into the correct order.
------------------------------
Date: Tue, 15 Jan 2008 09:45:03 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: How to detect text charset (UTF-8 or Latin-1)
Message-Id: <0520fda2-8b5b-4f1c-af7b-4794e9528783@f47g2000hsd.googlegroups.com>
On Jan 15, 11:59 am, Thomas Armstrong <tarmstr...@gmail.com> wrote:
> Hi.
>
> I'm creating a Perl script extracting text from a webpage using LWP,
> and want to check if text is UTF-8 or Latin-1 encoded?
>
> Is there any known function? I don't know if "use utf8;" is enough
>
> Thank you very much in advance.
Parse the Content-type header, for example:
content="text/html; charset=UTF-8"
Web pages that lie or omit the Content-type are not scarce,
unfortunately.
------------------------------
Date: Tue, 15 Jan 2008 07:30:34 -0800 (PST)
From: bwooster47 <bwooster47@gmail.com>
Subject: mod_perl ignoring changed to $ENV{{PATH}?
Message-Id: <2577aa35-18b2-404d-96ca-abbfa887a108@f47g2000hsd.googlegroups.com>
I've narrowed down to a simple script a problem where it looks like
when running under mod_perl, it does not support changes to the
$ENV{PATH} variable - it does require the assignment to avoid the
tainting, but then any assignment itself does not take effect - I
added /usr/local/bin to PATH, but am unable to execute commands in
that folder when running under mod_perl.
Could not find anything about this in the mod_perl web pages, but a
Usenet search seems to suggest that mod_perl only honors PerlSetEnv
PATH in config, and does not honor PATH changes in the script? That
does not sound right, what about the cases where a PATH change is
needed for some scripts only, so a global PerlSetEnv would be too
much.
Example - for testing, I copied /bin/echo to /usr/local/bin/echo, and
then ran this script - it runs fine when run under the shell, but when
run under Apache + mod_perl, it fails.
Script:
#!/usr/bin/perl -Tw
print "Content-type: text/plain\n\n";
$ENV{PATH} = "/bin:/usr/bin:/usr/local/bin:";
foreach ( "echo", "myecho", "/usr/local/bin/myecho") {
print "------ Testing command '$_'\n";
my $string = `$_ testing execution of '$_'`;
print " failed to execute '$_', \$? is $?/" . ($? >> 8) . " : $!
\n"
if ($? != 0);
print " \$string is: $string\n";
}
Shell output (perl -Tw script)
Content-type: text/plain
------ Testing command 'echo'
$string is: testing execution of echo
------ Testing command 'myecho'
$string is: testing execution of myecho
------ Testing command '/usr/local/bin/myecho'
$string is: testing execution of /usr/local/bin/myecho
Web page output - this fails to execute myecho without the path:
------ Testing command 'echo'
$string is: testing execution of echo
------ Testing command 'myecho'
failed to execute 'myecho', $? is 32512/127 :
$string is:
------ Testing command '/usr/local/bin/myecho'
$string is: testing execution of /usr/local/bin/myecho
------------------------------
Date: Tue, 15 Jan 2008 17:29:59 +0100
From: =?ISO-8859-1?Q?Andreas_P=FCrzer?= <pue@gmx.net>
Subject: Re: Referencing modules nested in a directory structure
Message-Id: <5v458sF1hrmmmU1@mid.individual.net>
Ben Morrow schrieb:
> Quoth David Smith <davidsmith@hotmail.com>:
>>
>> I'm coming to Perl from a Java background... where you import classes
>>using a fully-qualified name, and then generally make use of it using
>>the base class name:
>>
>>import myapp.dataojects.User;
>>...
>>User myUser = new User();
>>
>> I've been emulating the same convention as far as organizing my Perl
>>modules in a directory structure based on functionality. However, I
>>find that when using them I have to always use the fully-qualified name:
>>
>>use MyApp::DataObjects::User;
>>...
>>my $myUser = MyApp::DataObjects::User->new();
>
>
> Yup.
>
>
>> Is there any syntax by which I could access Perl objects by using the
>>object name alone, rather than the fully-qualified name? Such as this:
>>
>>use MyApp::DataObjects::User;
>>...
>>my $myUser = User->new();
>
>
> Nope, sorry :(. This is one of the flaws in Perl's package system, IMHO.
> One thing that may allieviate the pain is that a package (class) name is
> simply a string in Perl, so you can use a variable:
>
> use MyApp::DataObjects::User;
>
> my $USER = 'MyApp::DataObjects::User';
>
> my $myUser = $USER->new;
>
> If you were feeling evil you could even export this variable from
> MA::DO::U by default.
>
Yet Another Approach (for OO-Modules at least):
use aliased 'MyApp::DataObjects::User';
my $myUser = User->new();
http://search.cpan.org/~ovid/aliased-0.21/lib/aliased.pm
Andreas Puerzer
--
Have Fun,
and if you can't have fun,
have someone else's fun.
The Beautiful South
------------------------------
Date: Tue, 15 Jan 2008 14:17:35 GMT
From: Jrgen Exner <jurgenex@hotmail.com>
Subject: Re: Shebang line management
Message-Id: <21gpo314dqv6016j2teeq5ktrjhkuksla0@4ax.com>
Steve <SteveSpamTrap@yahoo.com> wrote:
> Are there any clever ways of dealing with portability of the "shebang"
>line... when moving Perl scripts across machines (and across operating
>systems), where the path to Perl may be different?
>
> For instance, I'm stuck doing initial development of some CGI scripts
>on a Windows machine, but then deploying them to a *nix Apache server.
>For each script, I'm manually cut-n-pasting to replace the:
>
>#!"c:/perl/bin/perl.exe"
>
> ... with:
>
>#!/usr/bin/perl
Windows doesn't care about the shebang line, therefore you can use the Unix
version even on Windows.
jue
------------------------------
Date: Tue, 15 Jan 2008 18:39:28 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: USEFUL perl SCRIPT: NTP verifier
Message-Id: <slrnfoprv7.mma.hjp-usenet2@hrunkner.hjp.at>
["Followup-To:" header set to comp.lang.perl.misc.]
On 2008-01-14 18:10, John Bokma <john@castleamber.com> wrote:
> Ignoramus5390 <ignoramus5390@NOSPAM.5390.invalid> wrote:
>> On 2008-01-14, John Bokma <john@castleamber.com> wrote:
>>> undef is the default value, I wouldn't assign it explicitly.
>>
>> I like this style. Makes it very explicit.
>
> IMO Perl programmers should know that the default is undef, and hence no
> need to assign undef.
Explicitely assigning undef does tell the reader something, though:
It means that from this point on the variable *needs* to have this value
- it isn't just undef because nobody assigned anything to it yet, it is
undef because the programmer wants it to be undef.
>>> Also, I recommend to support at least -h / --help.
>>
>> Is there some standard way of doing it?
>
> Perl Best Practices (recommended) recommends:
>
> --usage - one line
> --help - --usage line followed by one-line
> summary of each option (in my experience
> the one-line is to strict)
> --version
> --man - complete documentation of the program
The Pod::Usage module makes implementing that very simple.
>>> If you need to explain what IDs mean it clearly shows that the names
>>> of your variables are not chosen well.
>>
>> They come from NTP specification.
>
> OK, clear. That's something you've read to write this, but someone who
> reads your program does not always have to be familiar with this
> documentation, nor has to read it first IMO.
The whole comment is copied verbatim from the specs. That's something I
do, too.
> my $roundtrip_delay = ($T4 - $T1) - ($T2 - $T3);
>
> v.s.
>
> my $roundtrip_delay = ( $destination_ts - $originate_ts )
> - ( $receive_ts - $transmit_ts );
>
> which is more readable?
The first, by far. $T1 to $T4 form a logical sequence. It is completely
clear what they are. I have no idea what the second version means:
Originated by whom? Received and transmitted by whom? And why is
"destination" a noun when all others are verbs? Does that mean something
special?
(Oh, and BTW, the formula is wrong: It must be
my $roundtrip_delay = ($T4 - $T1) - ($T2 - $T2);
RFC 2030 contains the same error - its corrected in 4330)
hp
------------------------------
Date: Tue, 15 Jan 2008 11:59:25 -0600
From: Ignoramus25819 <ignoramus25819@NOSPAM.25819.invalid>
Subject: Re: USEFUL perl SCRIPT: NTP verifier
Message-Id: <O8ydnZ_A0YTgaRHanZ2dnUVZ_jCdnZ2d@giganews.com>
On 2008-01-15, Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
> ["Followup-To:" header set to comp.lang.perl.misc.]
> On 2008-01-14 18:10, John Bokma <john@castleamber.com> wrote:
>> Ignoramus5390 <ignoramus5390@NOSPAM.5390.invalid> wrote:
>>> On 2008-01-14, John Bokma <john@castleamber.com> wrote:
>>>> undef is the default value, I wouldn't assign it explicitly.
>>>
>>> I like this style. Makes it very explicit.
>>
>> IMO Perl programmers should know that the default is undef, and hence no
>> need to assign undef.
>
> Explicitely assigning undef does tell the reader something, though:
> It means that from this point on the variable *needs* to have this value
> - it isn't just undef because nobody assigned anything to it yet, it is
> undef because the programmer wants it to be undef.
Yep. This also means "no, I did not forget to assign its value".
i
------------------------------
Date: 15 Jan 2008 18:55:57 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: USEFUL perl SCRIPT: NTP verifier
Message-Id: <Xns9A26838E6761Bcastleamber@130.133.1.4>
"Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
> (Oh, and BTW, the formula is wrong: It must be
>
> my $roundtrip_delay = ($T4 - $T1) - ($T2 - $T2);
^ ^
Heh, I rest my case >:-D
--
John Bokma http://johnbokma.com/
------------------------------
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 1198
***************************************