[30701] in Perl-Users-Digest
Perl-Users Digest, Issue: 1946 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 27 00:09:41 2008
Date: Sun, 26 Oct 2008 21:09:10 -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, 26 Oct 2008 Volume: 11 Number: 1946
Today's topics:
dealing with time <dontmewithme@got.it>
Re: dealing with time <rvtol+news@isolution.nl>
Re: dealing with time <placebo@petergreen.id.au>
Re: dealing with time <someone@example.com>
Re: dealing with time <dontmewithme@got.it>
Re: dealing with time <hjp-usenet2@hjp.at>
Re: dealing with time <jurgenex@hotmail.com>
Re: dealing with time <dontmewithme@got.it>
Re: dealing with time <jurgenex@hotmail.com>
Re: dealing with time <dontmewithme@got.it>
Re: dealing with time <jurgenex@hotmail.com>
Re: dealing with time <mgjv@heliotrope.com.au>
Re: dealing with time <someone@example.com>
Re: dealing with time <dontmewithme@got.it>
Re: dealing with time <jurgenex@hotmail.com>
Re: dealing with time (Doug Miller)
Re: FAQ 4.57 What happens if I add or remove keys from xhoster@gmail.com
Re: FAQ 4.69 How can I make the Perl equivalent of a C <hjp-usenet2@hjp.at>
Re: Filehandle STDIN reopened as $fh1 only for output <hjp-usenet2@hjp.at>
Re: open(@_): Do not expect to get ARRAY(0x88a4c0) argu <hjp-usenet2@hjp.at>
Re: open(@_): Do not expect to get ARRAY(0x88a4c0) argu <whynot@pozharski.name>
Re: perl module to write on a var <ced@blv-sam-01.ca.boeing.com>
Re: Unix, Perl, IE, and Excel <bart.lateur@pandora.be>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 26 Oct 2008 09:37:41 +0100
From: Larry <dontmewithme@got.it>
Subject: dealing with time
Message-Id: <dontmewithme-E7A2FF.09374026102008@news.tin.it>
Hi,
I'm using File::stat to get the last mod time of a file:
my $sb = stat $file;
my $lmod = $sb->mtime;
Now I would like know how many minutes ago (from now) was that file
modified. Can it actually be done?
thanks
------------------------------
Date: Sun, 26 Oct 2008 10:53:04 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: dealing with time
Message-Id: <ge1i71.qc.1@news.isolution.nl>
Larry schreef:
> my $sb = stat $file;
> my $lmod = $sb->mtime;
>
> Now I would like know how many minutes ago (from now) was that file
> modified. Can it actually be done?
for f in stat time; do perldoc -f $f; done
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Sun, 26 Oct 2008 10:33:04 GMT
From: "Peter Wyzl" <placebo@petergreen.id.au>
Subject: Re: dealing with time
Message-Id: <AHXMk.8581$sc2.6283@news-server.bigpond.net.au>
"Larry" <dontmewithme@got.it> wrote in message
news:dontmewithme-E7A2FF.09374026102008@news.tin.it...
> Hi,
>
> I'm using File::stat to get the last mod time of a file:
>
> my $sb = stat $file;
> my $lmod = $sb->mtime;
>
> Now I would like know how many minutes ago (from now) was that file
> modified. Can it actually be done?
Since both time now and time thern are given in seconds (since the epoch
which varies by system), a bit of basic mathematics derives the result.
P
------------------------------
Date: Sun, 26 Oct 2008 06:08:16 -0700
From: "John W. Krahn" <someone@example.com>
Subject: Re: dealing with time
Message-Id: <0ZZMk.16717$TX6.562@newsfe06.iad>
Larry wrote:
>
> I'm using File::stat to get the last mod time of a file:
>
> my $sb = stat $file;
> my $lmod = $sb->mtime;
>
> Now I would like know how many minutes ago (from now) was that file
> modified. Can it actually be done?
my $minutes_last_modified = 1440 * -M $file;
John
--
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, 26 Oct 2008 17:31:46 +0100
From: Larry <dontmewithme@got.it>
Subject: Re: dealing with time
Message-Id: <dontmewithme-01B62D.17314626102008@news.tin.it>
In article <AHXMk.8581$sc2.6283@news-server.bigpond.net.au>,
"Peter Wyzl" <placebo@petergreen.id.au> wrote:
> Since both time now and time thern are given in seconds (since the epoch
> which varies by system), a bit of basic mathematics derives the result.
in fact I got this:
use File::stat;
my $file = "Mondo.pdf";
my $sb = stat $file;
my $lmod = $sb->mtime;
my $tnow = time;
my $diff = $tnow - $lmod;
Is there anyway to sprintf the $diff value to rappresent: hours, mins,
secs ??
thanks
------------------------------
Date: Sun, 26 Oct 2008 17:37:00 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: dealing with time
Message-Id: <slrngg975c.cps.hjp-usenet2@hrunkner.hjp.at>
On 2008-10-26 13:08, John W. Krahn <someone@example.com> wrote:
> Larry wrote:
>> I'm using File::stat to get the last mod time of a file:
>>
>> my $sb = stat $file;
>> my $lmod = $sb->mtime;
>>
>> Now I would like know how many minutes ago (from now) was that file
>> modified. Can it actually be done?
>
> my $minutes_last_modified = 1440 * -M $file;
Nope. -M computes the difference between the modification time and the
time the program was started. There may be a considerable difference
between "when the program was started" and "now".
hp
------------------------------
Date: Sun, 26 Oct 2008 09:59:32 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: dealing with time
Message-Id: <no79g4925c67blu74nee4ebc9elj36fn5q@4ax.com>
Larry <dontmewithme@got.it> wrote:
>Is there anyway to sprintf the $diff value to rappresent: hours, mins,
>secs ??
Not to make too fine a point but isn't that basic arithmetic at second
grade level?
Of course, there is always Time::Format, too.
jue
------------------------------
Date: Sun, 26 Oct 2008 18:18:51 +0100
From: Larry <dontmewithme@got.it>
Subject: Re: dealing with time
Message-Id: <dontmewithme-676161.18185126102008@news.tin.it>
In article <no79g4925c67blu74nee4ebc9elj36fn5q@4ax.com>,
J?rgen Exner <jurgenex@hotmail.com> wrote:
> Not to make too fine a point but isn't that basic arithmetic at second
> grade level?
well, I actually am doing the following:
use File::stat;
my $file = "time.pl";
my $sb = stat $file;
my $lmod = $sb->mtime;
my $tnow = time;
my $diff = $tnow - $lmod;
my ($sec,$min,$hour) = (localtime($diff))[0,1,2];
my $time = sprintf( "%1d hr %1d mins %1d secs", $hour - 1, $min, $sec );
Now, I would like to keep showing hours like 25,26 etc... (not days) any
ideas?
thanks
------------------------------
Date: Sun, 26 Oct 2008 10:29:23 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: dealing with time
Message-Id: <o5a9g45irss9e27l9fthpj3m6bq6hb316g@4ax.com>
Larry <dontmewithme@got.it> wrote:
>In article <no79g4925c67blu74nee4ebc9elj36fn5q@4ax.com>,
> J?rgen Exner <jurgenex@hotmail.com> wrote:
>
>> Not to make too fine a point but isn't that basic arithmetic at second
>> grade level?
>
>Now, I would like to keep showing hours like 25,26 etc... (not days) any
>ideas?
Seconds modulo (60*60)?
jue
------------------------------
Date: Sun, 26 Oct 2008 21:45:29 +0100
From: Larry <dontmewithme@got.it>
Subject: Re: dealing with time
Message-Id: <dontmewithme-FC8EB1.21452926102008@news.tin.it>
In article <o5a9g45irss9e27l9fthpj3m6bq6hb316g@4ax.com>,
J?rgen Exner <jurgenex@hotmail.com> wrote:
> Seconds modulo (60*60)?
I really don't get that. What I'm trying to do is:
59 secs
1 min 0 secs
59 min 0 secs
1 hr 0 min 0 secs
24 hr 0 min 0 secs
25 hr 0 min 0 secs
------------------------------
Date: Sun, 26 Oct 2008 14:54:51 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: dealing with time
Message-Id: <4mo9g4d3nq62qtmkmokc646llllk9ihe3h@4ax.com>
Larry <dontmewithme@got.it> wrote:
>In article <o5a9g45irss9e27l9fthpj3m6bq6hb316g@4ax.com>,
> J?rgen Exner <jurgenex@hotmail.com> wrote:
>
>> Seconds modulo (60*60)?
>
>I really don't get that. What I'm trying to do is:
Sorry, that was very confusing, indeed.
Try
use warnings; use strict;
my $seconds = 123456;
my $s = $seconds % 60;
my $m = (($seconds - $s) % (60*60))/60;
my $h = ($seconds - $m*60 - $s) / (60*60);
print "$seconds seconds are $h hours, $m minutes, and $s
seconds\n";
jue
------------------------------
Date: Mon, 27 Oct 2008 09:17:12 +1100
From: Martien Verbruggen <mgjv@heliotrope.com.au>
Subject: Re: dealing with time
Message-Id: <slrngg9r38.f43.mgjv@mgjv.heliotrope.home>
On Sun, 26 Oct 2008 21:45:29 +0100,
Larry <dontmewithme@got.it> wrote:
> In article <o5a9g45irss9e27l9fthpj3m6bq6hb316g@4ax.com>,
> J?rgen Exner <jurgenex@hotmail.com> wrote:
>
>> Seconds modulo (60*60)?
>
> I really don't get that. What I'm trying to do is:
The modulus operator is %. It does an integer division of two numbers,
and gives you the remainder. Together with division, this can be used to
do what you want (check the perlop documentation for more detailed
information on the operator as implemented in Perl, and Google for more
information about the mathematics.).
my $seconds = int $diff % 60;
my $minutes = int ($diff/60) % 60;
my $hours = int $diff/3600;
printf "$file: %02d:%02d:%02d\n", $hours, $minutes, $seconds;
note that 3600 comes from 60 * 60. I use int() here to make sure that
the three variables contain whole numbers. The %d in the printf format
would also get rid of any fractional part, but I think this is neater.
You should remember this technique. It's rather fundamental when you
need to work with numbers.
Martien
--
|
Martien Verbruggen | That's not a lie, it's a terminological
| inexactitude.
|
------------------------------
Date: Sun, 26 Oct 2008 16:20:07 -0700
From: "John W. Krahn" <someone@example.com>
Subject: Re: dealing with time
Message-Id: <CW6Nk.16822$TX6.15955@newsfe06.iad>
Peter J. Holzer wrote:
> On 2008-10-26 13:08, John W. Krahn <someone@example.com> wrote:
>> Larry wrote:
>>> I'm using File::stat to get the last mod time of a file:
>>>
>>> my $sb = stat $file;
>>> my $lmod = $sb->mtime;
>>>
>>> Now I would like know how many minutes ago (from now) was that file
>>> modified. Can it actually be done?
>> my $minutes_last_modified = 1440 * -M $file;
>
> Nope. -M computes the difference between the modification time and the
> time the program was started. There may be a considerable difference
> between "when the program was started" and "now".
$^T = time;
my $minutes_last_modified = 1440 * -M $file;
John
--
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: Mon, 27 Oct 2008 00:36:22 +0100
From: Larry <dontmewithme@got.it>
Subject: Re: dealing with time
Message-Id: <dontmewithme-755C43.00362227102008@news.tin.it>
In article <4mo9g4d3nq62qtmkmokc646llllk9ihe3h@4ax.com>,
J?rgen Exner <jurgenex@hotmail.com> wrote:
> print "$seconds seconds are $h hours, $m minutes, and $s
> seconds\n";
the code worked great...now I would love to show hours if $h has value >
0, minutes if $m > 0.
the thing is if I get "1 hour, 0 min, 10 secs" min won't show up...this
is what I'm stuck at!
just out of interest; I tried to run the code you posted with $seconds =
time; it gave me: 340295 hours, 34 minutes, and 20 seconds is the the
actaul hours since 1 jan 1970?
thanks
------------------------------
Date: Sun, 26 Oct 2008 17:43:57 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: dealing with time
Message-Id: <ct2ag4pp8eagjmcn3sn20dt20bdc76fqc9@4ax.com>
Larry <dontmewithme@got.it> wrote:
>In article <4mo9g4d3nq62qtmkmokc646llllk9ihe3h@4ax.com>,
> J?rgen Exner <jurgenex@hotmail.com> wrote:
>
>> print "$seconds seconds are $h hours, $m minutes, and $s
>> seconds\n";
>
>the code worked great...now I would love to show hours if $h has value >
>0, minutes if $m > 0.
Oh, please.......
print "$seconds seconds are ";
print "$h hours, " if $h;
print "$m minutes, " if $m;
print "$s seconds" if $s;
print "\n";
If you need more fancyful formatting, like no plural 's' for single
values or correct punctuation if one part is omitted, then you need to
be more elaborate in your if conditions and differentiate between more
cases.
>just out of interest; I tried to run the code you posted with $seconds =
>time; it gave me: 340295 hours, 34 minutes, and 20 seconds is the the
>actaul hours since 1 jan 1970?
Let's see: 340295 / 24 / 365 = 38.8 years (minus a few leap days).
Well, late 2008 - 38.8 years looks like early 1970 to me.
jue
------------------------------
Date: Mon, 27 Oct 2008 02:11:33 GMT
From: spambait@milmac.com (Doug Miller)
Subject: Re: dealing with time
Message-Id: <cz8Nk.4524$as4.1160@nlpi069.nbdc.sbc.com>
In article <dontmewithme-755C43.00362227102008@news.tin.it>, Larry <dontmewithme@got.it> wrote:
>In article <4mo9g4d3nq62qtmkmokc646llllk9ihe3h@4ax.com>,
> J?rgen Exner <jurgenex@hotmail.com> wrote:
>
>> print "$seconds seconds are $h hours, $m minutes, and $s
>> seconds\n";
>
>the code worked great...now I would love to show hours if $h has value >
>0, minutes if $m > 0.
>
>the thing is if I get "1 hour, 0 min, 10 secs" min won't show up...this
>is what I'm stuck at!
Are you familiar with the 'if' command??
>just out of interest; I tried to run the code you posted with $seconds =
>time; it gave me: 340295 hours, 34 minutes, and 20 seconds is the the
>actaul hours since 1 jan 1970?
Are you honestly unable to figure that out on your own?
------------------------------
Date: 27 Oct 2008 01:17:18 GMT
From: xhoster@gmail.com
Subject: Re: FAQ 4.57 What happens if I add or remove keys from a hash while iterating over it?
Message-Id: <20081026211746.034$1g@newsreader.com>
PerlFAQ Server <brian@stonehenge.com> wrote:
> This is an excerpt from the latest version perlfaq4.pod, which
> comes with the standard Perl distribution. These postings aim to
> reduce the number of repeated questions as well as allow the community
> to review and update the answers. The latest version of the complete
> perlfaq is at http://faq.perl.org .
>
> --------------------------------------------------------------------
>
> 4.57: What happens if I add or remove keys from a hash while iterating
> over it?
>
> (contributed by brian d foy)
>
> The easy answer is "Don't do that!"
>
> If you iterate through the hash with each(), you can delete the key
> most recently returned without worrying about it. If you delete or
> add other keys, the iterator may skip or double up on them since perl
> may rearrange the hash table. See the entry for "each()" in perlfunc.
I think that we have established that you can safely delete *any* key,
including the one just returned. It is only adding keys that may cause the
hash table to be re-arranged and thus cause the iterator to skip or double
up.
Is this behavior likely enough to change that the caution against deleting
should be retained in the FAQ just in case things change?
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, 26 Oct 2008 17:40:58 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 4.69 How can I make the Perl equivalent of a C structure/C++ class/hash or array of hashes or arrays?
Message-Id: <slrngg97cr.cps.hjp-usenet2@hrunkner.hjp.at>
On 2008-10-22 07:03, PerlFAQ Server <brian@stonehenge.com> wrote:
> --------------------------------------------------------------------
>
> 4.69: How can I make the Perl equivalent of a C structure/C++ class/hash or array of hashes or arrays?
>
> Usually a hash ref, perhaps like this:
>
> $record = {
> NAME => "Jason",
> EMPNO => 132,
> TITLE => "deputy peon",
> AGE => 23,
> SALARY => 37_000,
> PALS => [ "Norbert", "Rhys", "Phineas"],
> };
>
> References are documented in perlref and the upcoming perlreftut.
^^^^^^^^
perlreftut has come up some time ago, I believe.
hp
------------------------------
Date: Sun, 26 Oct 2008 17:30:23 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Filehandle STDIN reopened as $fh1 only for output
Message-Id: <slrngg96p1.cps.hjp-usenet2@hrunkner.hjp.at>
On 2008-10-26 01:15, Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
><hjp-usenet2@hjp.at>], who wrote in article <slrngg5p2v.rj6.hjp-usenet2@hrunkner.hjp.at>:
>> On 2008-10-23 15:34, xhoster@gmail.com <xhoster@gmail.com> wrote:
>> > Tad J McClellan <tadmc@seesig.invalid> wrote:
>> >> Let's see what perldiag says about that message:
>> >>
>> >> =item Filehandle STDIN reopened as %s only for output
>> >>
>> >> (W io) You opened for writing a filehandle that got the same
>> >> filehandle id as STDIN. This occurred because you closed STDIN
>> >> previously.
>> >
>> > But that is a pretty useless explanation. OK, so some file handle got
>> > opened to some file descriptor.
>
>> It is not "some filehandle", it is STDIN.
>
> No it's not.
Right.
[...]
> The message we are discussing is VERY misleading.
Misleading enough that I went off on a tangent and wrote about a quite
different problem than the one at hand. Sorry for the confusion.
hp
------------------------------
Date: Sun, 26 Oct 2008 17:46:52 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: open(@_): Do not expect to get ARRAY(0x88a4c0) arguments
Message-Id: <slrngg97ns.cps.hjp-usenet2@hrunkner.hjp.at>
On 2008-10-22 21:13, Eric Pozharski <whynot@pozharski.name> wrote:
>> I found the problem. It seems to be a bug in autodie...
^^^^^^^
>
> Not for me
>
> perl -wle '
> open $out, q{|-}, q{/bin/ls}, qw(-s -i /) or die;
> print while(<$out>);
> close $out;
> wait;'
You didn't use autodie, so how does this show the absence of a bug in
autodie?
hp
------------------------------
Date: Mon, 27 Oct 2008 00:37:31 +0200
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: open(@_): Do not expect to get ARRAY(0x88a4c0) arguments
Message-Id: <slrngg9s9b.mbi.whynot@orphan.zombinet>
On 2008-10-26, Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
> On 2008-10-22 21:13, Eric Pozharski <whynot@pozharski.name> wrote:
>>> I found the problem. It seems to be a bug in autodie...
> ^^^^^^^
>>
>> Not for me
>>
>> perl -wle '
>> open $out, q{|-}, q{/bin/ls}, qw(-s -i /) or die;
>> print while(<$out>);
>> close $out;
>> wait;'
>
> You didn't use autodie, so how does this show the absence of a bug in
> autodie?
Yup, it doesn't.
--
Torvalds' goal for Linux is very simple: World Domination
------------------------------
Date: Sun, 26 Oct 2008 20:35:53 -0700 (PDT)
From: "C.DeRykus" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: perl module to write on a var
Message-Id: <8ff3a884-311a-40e0-8883-122155d05ba8@b31g2000prb.googlegroups.com>
On Oct 25, 5:49 am, Larry <dontmewit...@got.it> wrote:
> Hi,
>
> I've been using a perl module that writes binary data on a file...now
> I would like to save this binary data on a var insted of on a file...the
> following si the code:
>
> my $_mp3 = MP3::Tag->new($file);
>
> my $_id3v2 = $_mp3->new_tag("ID3v2");
> $_id3v2->add_frame($key, $value);
> $_id3v2->write_tag();
>
> I'd rather save the data on a var kept in memory (I must not save the
> data on a file!)
>
> so is there anyway to have my $_mp3 = MP3::Tag->new($file); point to a
> var?
>
Probably not unless MP3::Tags'
docs hint otherwise. To be sure, you might want to look inside
the constructor itself:
perldoc -m MP3::Tag | perl -ne 'print if /^sub new/../^}/'
--
Charles DeRykus
------------------------------
Date: Sun, 26 Oct 2008 14:24:01 +0100
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Unix, Perl, IE, and Excel
Message-Id: <npr8g453n7dsi455q185d4qajdofkgi103@4ax.com>
cartercc wrote:
>Here's the question: I have a user who wants the data embedded in an
>Excel worksheet right on the web page. Can this be done? The web
>server is Apache coming from Linux, but Userland is 100% Windows.
Yes. Look at Spreadsheet::WriteExcel, a Pure Perl module to generate an
Excel file (pre 2007). No Windows or MS Office required.
--
Bart.
------------------------------
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 1946
***************************************