[32745] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4009 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 7 09:09:38 2013

Date: Wed, 7 Aug 2013 06:09:06 -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, 7 Aug 2013     Volume: 11 Number: 4009

Today's topics:
    Re: configuring STD* IO to use locale's encoding? (Seymour J.)
    Re: configuring STD* IO to use locale's encoding? <hjp-usenet3@hjp.at>
    Re: configuring STD* IO to use locale's encoding? <oneingray@gmail.com>
    Re: fast scan <derykus@gmail.com>
    Re: fast scan <rweikusat@mssgmbh.com>
    Re: fast scan <derykus@gmail.com>
    Re: fast scan <nospam.gravitalsun.noadsplease@hotmail.noads.com>
        Merge files <nospam.gravitalsun.noadsplease@hotmail.noads.com>
    Re: PAUSE vs. $VERSION <oneingray@gmail.com>
    Re: print and the . operator ?? kalyan.nsmetla@gmail.com
    Re: print and the . operator ?? kalyan.nsmetla@gmail.com
    Re: print and the . operator ?? kalyan.nsmetla@gmail.com
        translate human-readable time shorthand <mathias@koerber.org>
    Re: translate human-readable time shorthand <framstag@rus.uni-stuttgart.de>
    Re: translate human-readable time shorthand <nospam.gravitalsun.noadsplease@hotmail.noads.com>
    Re: translate human-readable time shorthand <oneingray@gmail.com>
    Re: translate human-readable time shorthand <peter@makholm.net>
    Re: translate human-readable time shorthand <nospam.gravitalsun.noadsplease@hotmail.noads.com>
    Re: translate human-readable time shorthand <rweikusat@mssgmbh.com>
    Re: translate human-readable time shorthand <rweikusat@mssgmbh.com>
    Re: translate human-readable time shorthand <oneingray@gmail.com>
    Re: translate human-readable time shorthand <rweikusat@mssgmbh.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 05 Aug 2013 22:28:41 -0400
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: configuring STD* IO to use locale's encoding?
Message-Id: <52005f59$14$fuzhry+tra$mr2ice@news.patriot.net>

In <87haf5lwic.fsf@violet.siamics.net>, on 08/04/2013
   at 07:56 AM, Ivan Shmakov <oneingray@gmail.com> said:

>	BTW, where is this pragma documented?

Pragmata.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org



------------------------------

Date: Wed, 7 Aug 2013 09:12:08 +0200
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: configuring STD* IO to use locale's encoding?
Message-Id: <slrnl03sq8.icm.hjp-usenet3@hrunkner.hjp.at>

On 2013-08-06 02:28, Shmuel Metz <spamtrap@library.lspace.org.invalid> wrote:
> In <87haf5lwic.fsf@violet.siamics.net>, on 08/04/2013
>    at 07:56 AM, Ivan Shmakov <oneingray@gmail.com> said:
>>	BTW, where is this pragma documented?
>
> Pragmata.

???

	hp


-- 
   _  | Peter J. Holzer    | Fluch der elektronischen Textverarbeitung:
|_|_) | Sysadmin WSR       | Man feilt solange an seinen Text um, bis
| |   | hjp@hjp.at         | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpat. -- Ralph Babel


------------------------------

Date: Wed, 07 Aug 2013 08:24:41 +0000
From: Ivan Shmakov <oneingray@gmail.com>
Subject: Re: configuring STD* IO to use locale's encoding?
Message-Id: <87fvulkiwm.fsf@violet.siamics.net>

>>>>> Peter J Holzer <hjp-usenet3@hjp.at> writes:
>>>>> On 2013-08-06 02:28, Shmuel Metz wrote:
>>>>> Ivan Shmakov <oneingray@gmail.com> said:

 >>> BTW, where is this pragma documented?

 >> Pragmata.

 > ???

	My guess is that "pragmata" is a plural for "pragma."
	(Cf. "schemata.")

	But should I be interested in /pragmata/ documentation,
	I wouldn't have used singulars ("is", "this") in the sentence.

-- 
FSF associate member #7257


------------------------------

Date: Tue, 06 Aug 2013 12:48:39 -0700
From: Charles DeRykus <derykus@gmail.com>
Subject: Re: fast scan
Message-Id: <ktrjvm$1bl$1@speranza.aioe.org>

On 8/6/2013 3:32 AM, Rainer Weikusat wrote:
> Charles DeRykus <derykus@gmail.com> writes:
>> On 8/5/2013 12:28 PM, Rainer Weikusat wrote:
> ...
>
> The solution is really simply to rate-limit requests being sent which
> can be accomplished by something as hideously arcane as doing
> a (subsecond) 'sleep' between two sends when using a dedicated sending thread/
> process (presumably, that's not something whose name looks like the
> German word for 'trainwreck' would ever consider) or using select with
> a suitable timeout to wait for replies between two sends. This
> 'parallelism' idea is inherently broken because replies aren't
> guaranteed to arrive.
>

> NB: I completely understand how to 'work around that' by employing a
> general-purpose timer implementation (which might even use a sensible
> algorithm for priority queues although this would really surprise me)
> combined with a general purpose 'coroutine' aka 'cooperative userspace
> threading' (Mark 45054) implementation with a combined size of 1E9
> LOC (25% were never executed so far, another 25% are executed but
> don't do anything useful, a further 25% workarounds for bugs in the
> remaining 25%).
>

Maybe, I'm confused but my understanding is that each boxcar on the 
"POE-Zug" fires off its icmp ping, waits for the user-configurable 
timeout, and gathers any/all responses. Overall send-rate is throttled 
with the configurable parallelism setting. If that rate is properly 
tuned to avoid saturating the network,  where does the train run off the 
tracks? (I'd guess even an alternative micro-sleep between requests 
might potentially bog down a network without tuning)

-- 
Charles DeRykus


------------------------------

Date: Wed, 07 Aug 2013 00:26:27 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: fast scan
Message-Id: <87ob9a7658.fsf@sapphire.mobileactivedefense.com>

Charles DeRykus <derykus@gmail.com> writes:
> On 8/6/2013 3:32 AM, Rainer Weikusat wrote:
>> Charles DeRykus <derykus@gmail.com> writes:
>>> On 8/5/2013 12:28 PM, Rainer Weikusat wrote:
>> ...
>>
>> The solution is really simply to rate-limit requests being sent

[...]

>> This 'parallelism' idea is inherently broken because replies aren't
>> guaranteed to arrive.

[...]

> Maybe, I'm confused but my understanding is that each boxcar on the
> "POE-Zug" fires off its icmp ping, waits for the user-configurable
> timeout, and gathers any/all responses.

This description assumes a full-fledged 'virtual thread' per ping but
it is generally correct: The 'parallelism' thing requires an
individual timeout per request in flight in order to keep going in
face of replies which may never arrive.

> Overall send-rate is throttled with the configurable parallelism
> setting.

'Send 1000 requests as fast as you can, then, do nothing for ten
seconds' is not the same as 'continue sending a request every 0.01s
for 10 seconds': Again simplifying things, 'an ethernet is binary': At
any given time, it is either 'in use' or 'not in use'. The bulk send
means it is 'in use' for a relatively long period of time at the
beginning and will be 'in use' for a similarly long period of time as
soon as the replies start arriving. Otherwise, it will be 'in use' for
many short time periods and 'be available' in between (the same is
true for resources on the sending/ receiving host where it means 'be
available to deal with replies').

> If that rate is properly tuned to avoid saturating the network,
> where does the train run off the tracks? (I'd guess even an
> alternative micro-sleep between requests might potentially bog down
> a network without tuning)

Even the slowest isosychronous injection of 'packets' into a
network might be the straw breaking the camel's back. That's why
'serious' general purpose algorithms for congestion avoidance are
adaptive (and usually not exactly simple). But it's getting late here,
I still have some (household) work to do and I'm not entirely
sober. Because of this, I'm now terminating this with another 'vulgar
appeal to common sense': Hearing works better when one stops shouting
more frequently.



------------------------------

Date: Tue, 06 Aug 2013 22:17:10 -0700
From: Charles DeRykus <derykus@gmail.com>
Subject: Re: fast scan
Message-Id: <ktsl9o$hlj$1@speranza.aioe.org>

On 8/6/2013 4:26 PM, Rainer Weikusat wrote:
> Charles DeRykus <derykus@gmail.com> writes:
>> On 8/6/2013 3:32 AM, Rainer Weikusat wrote:
>>> Charles DeRykus <derykus@gmail.com> writes:
>>>> On 8/5/2013 12:28 PM, Rainer Weikusat wrote:
>>> ...
>>>
>>> The solution is really simply to rate-limit requests being sent
>
> ..
>
>> Overall send-rate is throttled with the configurable parallelism
>> setting.
>
> 'Send 1000 requests as fast as you can, then, do nothing for ten
> seconds' is not the same as 'continue sending a request every 0.01s
> for 10 seconds': Again simplifying things, 'an ethernet is binary': At
> any given time, it is either 'in use' or 'not in use'. The bulk send
> means it is 'in use' for a relatively long period of time at the
> beginning and will be 'in use' for a similarly long period of time as
> soon as the replies start arriving. Otherwise, it will be 'in use' for
> many short time periods and 'be available' in between (the same is
> true for resources on the sending/ receiving host where it means 'be
> available to deal with replies').
>

Yes, thanks for the clarification. POE auto-sizes various default 
settings including 'Parallelism' based on OS and other factors. I notice 
there's also a FAQ strategy to introduce pauses within its pseudo-kernel 
if the requirement is there. Clearly any approach will require tuning.

 >>
 ...

-- 
Charles DeRykus


------------------------------

Date: Wed, 07 Aug 2013 09:51:06 +0300
From: George Mpouras <nospam.gravitalsun.noadsplease@hotmail.noads.com>
Subject: Re: fast scan
Message-Id: <ktsqnf$v96$1@news.ntua.gr>

Στις 7/8/2013 08:17, ο/η Charles DeRykus έγραψε:
> On 8/6/2013 4:26 PM, Rainer Weikusat wrote:
>> Charles DeRykus <derykus@gmail.com> writes:
>>> On 8/6/2013 3:32 AM, Rainer Weikusat wrote:
>>>> Charles DeRykus <derykus@gmail.com> writes:
>>>>> On 8/5/2013 12:28 PM, Rainer Weikusat wrote:
>>>> ...
>>>>
>>>> The solution is really simply to rate-limit requests being sent
>>
>> ..
>>
>>> Overall send-rate is throttled with the configurable parallelism
>>> setting.
>>
>> 'Send 1000 requests as fast as you can, then, do nothing for ten
>> seconds' is not the same as 'continue sending a request every 0.01s
>> for 10 seconds': Again simplifying things, 'an ethernet is binary': At
>> any given time, it is either 'in use' or 'not in use'. The bulk send
>> means it is 'in use' for a relatively long period of time at the
>> beginning and will be 'in use' for a similarly long period of time as
>> soon as the replies start arriving. Otherwise, it will be 'in use' for
>> many short time periods and 'be available' in between (the same is
>> true for resources on the sending/ receiving host where it means 'be
>> available to deal with replies').
>>
>
> Yes, thanks for the clarification. POE auto-sizes various default
> settings including 'Parallelism' based on OS and other factors. I notice
> there's also a FAQ strategy to introduce pauses within its pseudo-kernel
> if the requirement is there. Clearly any approach will require tuning.
>
>  >>
> ...
>


can you run the POE stuff while monitor cpu and network and reply your 
findings ;




------------------------------

Date: Wed, 07 Aug 2013 13:31:23 +0300
From: George Mpouras <nospam.gravitalsun.noadsplease@hotmail.noads.com>
Subject: Merge files
Message-Id: <ktt7kg$221k$1@news.ntua.gr>


# I am writing something, so here is a subroutine of it, you may like.
# It simple merge files, a little bit more careful than usual



#!/usr/bin/perl
use strict;
use warnings;


MergeFiles( DIR => 'r:/tmp/dir' , OUTPUTFILE => '/tmp/big.txt') or die 
"oups $^E\n";


# Merge all tiles that exist in a directory to a big one.
# It tries to be clever by merging files to the biggest of them.
# Also it prefers the newer files first to help any potential sort later

# MergeFiles( DIR => '/tmp' , OUTPUTFILE => /tmp/big' ) || die;
#
sub MergeFiles
{
my %option = @_;
exists $option{$_} || die "The \"$_\" argument is missing from ".(caller 
0)[3]."\n" foreach qw/DIR OUTPUTFILE/;
opendir DIRFORMERGEFILES,  $option{'DIR'} or return 0;
my @File;
while (readdir DIRFORMERGEFILES) {
my $node = "$option{'DIR'}/$_";
next unless -f $node;
push @File, [ $node , -s _ , -M _ ] }
closedir DIRFORMERGEFILES;
return 1 if -1 == $#File;
my @FileSorted;

	for ( sort { $b->[1] <=> $a->[1] || $a->[2] <=> $b->[2] } @File )
	{
	push @FileSorted, $_->[0]	
	}

@File=();

	if (scalar @FileSorted > 1)
	{
	# Put a final new line character at the bigger file we are going to 
merge to in case it does not exist
	my	$data;
	open    BIGERFILETOMERGE, '<', $FileSorted[0] or return 0;
	binmode BIGERFILETOMERGE, ':raw';
	seek    BIGERFILETOMERGE, -1    , 2;
	read    BIGERFILETOMERGE, $data , 1;
	close   BIGERFILETOMERGE;
	my	$the_bigger_file_a_final_new_line_character = $data eq chr 10 ? 1 : 0;
	open    BIGERFILETOMERGE, '>>', $FileSorted[0] or return 0;
	print   BIGERFILETOMERGE "\n" unless 
$the_bigger_file_a_final_new_line_character;
	
	for (my $i=1; $i < @FileSorted; $i++) {
	open    MERGETHISFILE, '<', $FileSorted[$i] or return 0;
	while (<MERGETHISFILE>) { next if /^\s*$/; chomp; s/\s*$//; print 
BIGERFILETOMERGE "$_\n" }
	close   MERGETHISFILE;
	unlink $FileSorted[$i] || die "Could not delete file 
\"$FileSorted[$i]\" because \"$^E\"\n" }
	close   BIGERFILETOMERGE;
	}

unless ($FileSorted[0] eq $option{'OUTPUTFILE'}) { 
rename($FileSorted[0], $option{OUTPUTFILE}) or die "Could not rename 
file \"$FileSorted[0]\" to \"$option{OUTPUTFILE}\" because \"$^E\"\n" }
return 1
}


------------------------------

Date: Wed, 07 Aug 2013 08:40:11 +0000
From: Ivan Shmakov <oneingray@gmail.com>
Subject: Re: PAUSE vs. $VERSION
Message-Id: <877gfxki6s.fsf@violet.siamics.net>

>>>>> Rainer Weikusat <rweikusat@mssgmbh.com> writes:
>>>>> Ivan Shmakov <oneingray@gmail.com> writes: [...]

 >> Do I understand it correctly that the "package PACKAGE VERSION" form
 >> is a (relatively) recent addition to Perl

 > According to www.perl.org, it was added with Perl 5.12.0 (released on
 > 2010/04/12).

	ACK, thanks!

	The "primary" Perl version of my interest is now 5.14.2 (which
	is the version included in Debian 7), but unless it proves to be
	too much a burden, I'd like to support older Perl versions,
	going as far back as 5.10.1 (which could be found in, e. g., the
	still supported Debian 6.0.)

	I've thus reverted back to the use of explicit "our $VERSION"
	forms in the just released Tree-Range-0.22 [1].

[1] news:87k3jyk60c.fsf@violet.siamics.net

-- 
FSF associate member #7257


------------------------------

Date: Tue, 6 Aug 2013 09:06:41 -0700 (PDT)
From: kalyan.nsmetla@gmail.com
Subject: Re: print and the . operator ??
Message-Id: <e827aee7-ad12-44bd-89ec-2f2fb3baf14c@googlegroups.com>

://www.web-design-hyderabad.in/seo-course-in-neredmet/


Contact for advisor : +91 9177522892

Web Design Hyderabad has a great demand and much more competition, But many=
 of companies are not able to provide good service for customers, The probl=
em might be because of design quality, not providing dynamic works like con=
tact form or may be client expecting more work with very low cost.

To work with Web Design in Hyderabad,  A designer should more honest with t=
he client, you have to be explain the work of cost exactly, If not a design=
er will be struggled one day with client, Every one knows a designer can do=
 any work but it takes time right, We have to cost as per our time

web design companies in hyderabad

Web design history

The Hypertext concept was invented by Ted Nelson in 60s, however it was use=
d only for some decades after. During 1992 to 1994 other developers started=
 adding up their own bits of HTML codes. HTML 1 tags and the HTML 2 born. A=
s internet faster now the Web designers are putting more HTML capabilities.=
 In 1995 more HTML tags have appeared and HTMl 3 was born. Now designers ha=
ve an lot of option to use HTML B tables and style sheets and many more. Th=
ey also have animated images, and Flash also introduced. It changed the who=
le landscape of web design from static to dynamic.

The first web site published in the World Wide Web history at sometime in A=
ugust of 1981. It was some 30 years ago, however the Internet born in the s=
ixties. It wasn=92t fast as today. However it was capable in transferring i=
nformation from one computer to another. Tim Berners was the first person w=
ho invented the World Wide Web. Tim Berners is British computer scientist. =
The First website launched in year 1990. on December 25 1990 with the help =
of Robert Cailliau and young student at CERN, Tim Berners implemented first=
 successful communication between a Hypertext Transfer Protocol (HTTP) patr=
on and server via Internet.


------------------------------

Date: Tue, 6 Aug 2013 09:07:12 -0700 (PDT)
From: kalyan.nsmetla@gmail.com
Subject: Re: print and the . operator ??
Message-Id: <742549e5-ad83-4e80-866f-66a678178375@googlegroups.com>

://www.web-design-hyderabad.in/seo-course-in-neredmet/


Contact for advisor : +91 9177522892

Web Design Hyderabad has a great demand and much more competition, But many=
 of companies are not able to provide good service for customers, The probl=
em might be because of design quality, not providing dynamic works like con=
tact form or may be client expecting more work with very low cost.

To work with Web Design in Hyderabad,  A designer should more honest with t=
he client, you have to be explain the work of cost exactly, If not a design=
er will be struggled one day with client, Every one knows a designer can do=
 any work but it takes time right, We have to cost as per our time

web design companies in hyderabad

Web design history

The Hypertext concept was invented by Ted Nelson in 60s, however it was use=
d only for some decades after. During 1992 to 1994 other developers started=
 adding up their own bits of HTML codes. HTML 1 tags and the HTML 2 born. A=
s internet faster now the Web designers are putting more HTML capabilities.=
 In 1995 more HTML tags have appeared and HTMl 3 was born. Now designers ha=
ve an lot of option to use HTML B tables and style sheets and many more. Th=
ey also have animated images, and Flash also introduced. It changed the who=
le landscape of web design from static to dynamic.

The first web site published in the World Wide Web history at sometime in A=
ugust of 1981. It was some 30 years ago, however the Internet born in the s=
ixties. It wasn=92t fast as today. However it was capable in transferring i=
nformation from one computer to another. Tim Berners was the first person w=
ho invented the World Wide Web. Tim Berners is British computer scientist. =
The First website launched in year 1990. on December 25 1990 with the help =
of Robert Cailliau and young student at CERN, Tim Berners implemented first=
 successful communication between a Hypertext Transfer Protocol (HTTP) patr=
on and server via Internet.


------------------------------

Date: Tue, 6 Aug 2013 09:07:44 -0700 (PDT)
From: kalyan.nsmetla@gmail.com
Subject: Re: print and the . operator ??
Message-Id: <ead3b2e5-e0b5-4f64-a0cf-6e1cb39bf1e7@googlegroups.com>

://www.web-design-hyderabad.in/seo-course-in-neredmet/


Contact for advisor : +91 9177522892

Web Design Hyderabad has a great demand and much more competition, But many=
 of companies are not able to provide good service for customers, The probl=
em might be because of design quality, not providing dynamic works like con=
tact form or may be client expecting more work with very low cost.

To work with Web Design in Hyderabad,  A designer should more honest with t=
he client, you have to be explain the work of cost exactly, If not a design=
er will be struggled one day with client, Every one knows a designer can do=
 any work but it takes time right, We have to cost as per our time

web design companies in hyderabad

Web design history

The Hypertext concept was invented by Ted Nelson in 60s, however it was use=
d only for some decades after. During 1992 to 1994 other developers started=
 adding up their own bits of HTML codes. HTML 1 tags and the HTML 2 born. A=
s internet faster now the Web designers are putting more HTML capabilities.=
 In 1995 more HTML tags have appeared and HTMl 3 was born. Now designers ha=
ve an lot of option to use HTML B tables and style sheets and many more. Th=
ey also have animated images, and Flash also introduced. It changed the who=
le landscape of web design from static to dynamic.

The first web site published in the World Wide Web history at sometime in A=
ugust of 1981. It was some 30 years ago, however the Internet born in the s=
ixties. It wasn=92t fast as today. However it was capable in transferring i=
nformation from one computer to another. Tim Berners was the first person w=
ho invented the World Wide Web. Tim Berners is British computer scientist. =
The First website launched in year 1990. on December 25 1990 with the help =
of Robert Cailliau and young student at CERN, Tim Berners implemented first=
 successful communication between a Hypertext Transfer Protocol (HTTP) patr=
on and server via Internet.


------------------------------

Date: Wed, 07 Aug 2013 12:00:19 +0800
From: =?UTF-8?B?TWF0aGlhcyBLxZFyYmVy?= <mathias@koerber.org>
Subject: translate human-readable time shorthand
Message-Id: <b6dv2jFbkjmU1@mid.individual.net>

I am looking for a module which can help
translate human input for durations such as

   3w4d20m10s
into seconds (2161210). Spaces inside the
input should be ignored. If it can accept
other formats, the better.

thanks


------------------------------

Date: Wed, 7 Aug 2013 06:36:03 +0000 (UTC)
From: Ulli Horlacher <framstag@rus.uni-stuttgart.de>
Subject: Re: translate human-readable time shorthand
Message-Id: <ktspsj$5eq$1@news2.informatik.uni-stuttgart.de>

Mathias K?rber <mathias@koerber.org> wrote:
> I am looking for a module which can help
> translate human input for durations such as
> 
>    3w4d20m10s
> into seconds (2161210). Spaces inside the
> input should be ignored. If it can accept
> other formats, the better.

This is easy:

sub seconds {
  local $_ = shift;
  my $seconds = 0;

  s/\s//g;
  
  $seconds += $1*60*60*24*7 if /(\d+)w/;
  $seconds += $1*60*60*24   if /(\d+)d/;
  $seconds += $1*60*60      if /(\d+)h/;
  $seconds += $1*60         if /(\d+)m/;
  $seconds += $1            if /(\d+)s/;
  
  return $seconds;
}

-- 
Ullrich Horlacher              Informationssysteme und Serverbetrieb
Rechenzentrum IZUS/TIK         E-Mail: horlacher@tik.uni-stuttgart.de
Universitaet Stuttgart         Tel:    ++49-711-68565868
Allmandring 30a                Fax:    ++49-711-682357
70550 Stuttgart (Germany)      WWW:    http://www.tik.uni-stuttgart.de/


------------------------------

Date: Wed, 07 Aug 2013 09:40:17 +0300
From: George Mpouras <nospam.gravitalsun.noadsplease@hotmail.noads.com>
Subject: Re: translate human-readable time shorthand
Message-Id: <ktsq35$tnt$1@news.ntua.gr>

# There is the correct answer and the fast one. Here is the fast one !



use strict;
use warnings;

print SecondThis(  '3w4d20m 10s' );
print SecondThis(  '2h 3s' );

# Number of seconds of a string like "3w4d 20m 10s"
#
# Y years
# M months
# d days
# w weeks
# h hours
# m minutes
# s seconfs
#
sub SecondThis
{
(local $_   = $_[0]) =~s/[^\dYMdwhms]+//g;
my $years   = /(\d+)\s*Y/ ? $^N : 0;
my $months  = /(\d+)\s*M/ ? $^N : 0;
my $days    = /(\d+)\s*d/ ? $^N : 0;
my $weeks   = /(\d+)\s*w/ ? $^N : 0;
my $hours   = /(\d+)\s*h/ ? $^N : 0;
my $minutes = /(\d+)\s*m/ ? $^N : 0;
my $seconds = /(\d+)\s*s/ ? $^N : 0;
$seconds+
(60*$minutes)+
(3600*$hours)+
(86400*$days)+
(604800*$weeks)+
(2592000*$months)+
(31536000*$years)
}




------------------------------

Date: Wed, 07 Aug 2013 08:31:41 +0000
From: Ivan Shmakov <oneingray@gmail.com>
Subject: Re: translate human-readable time shorthand
Message-Id: <87bo59kiky.fsf@violet.siamics.net>

>>>>> Ulli Horlacher <framstag@rus.uni-stuttgart.de> writes:
>>>>> Mathias K?rber <mathias@koerber.org> wrote:

 >> I am looking for a module which can help translate human input for
 >> durations such as

 >> 3w4d20m10s into seconds (2161210).  Spaces inside the input should
 >> be ignored.  If it can accept other formats, the better.

 > This is easy:

 > sub seconds {

 >   local $_ = shift; my $seconds = 0;

 >   s/\s//g;

	This one above seems a bit redundant...

 >   $seconds += $1*60*60*24*7 if /(\d+)w/;
 >   $seconds += $1*60*60*24   if /(\d+)d/;

	... given that these REs are already going to ignore spaces.

	And not only spaces, BTW.  Consider, e. g.:

   my $r
       = seconds ("Hello, wor1d!");

	Now $r is 86400.

[...]

-- 
FSF associate member #7257


------------------------------

Date: Wed, 07 Aug 2013 10:46:44 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: translate human-readable time shorthand
Message-Id: <87wqnxga6j.fsf@vps1.hacking.dk>

George Mpouras <nospam.gravitalsun.noadsplease@hotmail.noads.com>
writes:

> # There is the correct answer and the fast one. Here is the fast one !

It would be nice to document, at least partly, where this answer is
incorrect.

 - It assumes 24 hours days. This assumption breaks twice a year in
locations observing summer time.

 - It assumes 30 days months, which is clearly an approximation.

 - It assumes 365 days yeas, which doesn't account for leap years.

 - It doesn't take leap seconds into account.

Depending on the scenario at least some of these assumptions might be
regarded as either valid or invalid.  

//Makholm


------------------------------

Date: Wed, 07 Aug 2013 12:28:58 +0300
From: George Mpouras <nospam.gravitalsun.noadsplease@hotmail.noads.com>
Subject: Re: translate human-readable time shorthand
Message-Id: <ktt3vf$1obj$1@news.ntua.gr>

Στις 7/8/2013 11:46, ο/η Peter Makholm έγραψε:
> George Mpouras <nospam.gravitalsun.noadsplease@hotmail.noads.com>
> writes:
>
>> # There is the correct answer and the fast one. Here is the fast one !
>
> It would be nice to document, at least partly, where this answer is
> incorrect.
>
>   - It assumes 24 hours days. This assumption breaks twice a year in
> locations observing summer time.
>
>   - It assumes 30 days months, which is clearly an approximation.
>
>   - It assumes 365 days yeas, which doesn't account for leap years.
>
>   - It doesn't take leap seconds into account.
>
> Depending on the scenario at least some of these assumptions might be
> regarded as either valid or invalid.
>
> //Makholm
>



You answer yourself.
Many many times customers, without thinking a lot, just saying, please 
automate the retirement of data that are e.g. older than 2 months !

So a very interesting conversation is started.
As I said there is the absolute correct solution but its out of scope of 
initial request.



------------------------------

Date: Wed, 07 Aug 2013 11:45:08 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: translate human-readable time shorthand
Message-Id: <87wqnx93uz.fsf@sapphire.mobileactivedefense.com>

Peter Makholm <peter@makholm.net> writes:
> George Mpouras <nospam.gravitalsun.noadsplease@hotmail.noads.com>
> writes:
>
>> # There is the correct answer and the fast one. Here is the fast one !
>
> It would be nice to document, at least partly, where this answer is
> incorrect.
>
>  - It assumes 24 hours days. This assumption breaks twice a year in
> locations observing summer time.
>
>  - It assumes 30 days months, which is clearly an approximation.
>
>  - It assumes 365 days yeas, which doesn't account for leap years.
>
>  - It doesn't take leap seconds into account.

While this is true, it already applies to the input data which uses
undefined units whose 'conventionally assumed meanings' are not really
well-defined: The exact meaning depends not only on a start date but
even on unpredictable, external events such as 'leap second
insertion'.


------------------------------

Date: Wed, 07 Aug 2013 11:52:39 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: translate human-readable time shorthand
Message-Id: <87siyl93ig.fsf@sapphire.mobileactivedefense.com>

Mathias Kőrber <mathias@koerber.org> writes:
> I am looking for a module which can help
> translate human input for durations such as
>
>    3w4d20m10s
> into seconds (2161210). Spaces inside the
> input should be ignored. If it can accept
> other formats, the better.

If you want to do this correctly, a start date is needed and the code
needs to calculate the 'target date' based on that. Eg, '3m starting
on March 15th' would mean 'June 15th', a period of 61 days, the same
starting on 'July 15' would mean 'September 15th', 62 days. After this
has been done, the target date can be converted into a second count
and the difference can be calculated.

It would be simpler to use an approximate unit definition and code
like the two examples posted in this thread.



------------------------------

Date: Wed, 07 Aug 2013 12:13:25 +0000
From: Ivan Shmakov <oneingray@gmail.com>
Subject: Re: translate human-readable time shorthand
Message-Id: <87wqnxitqy.fsf@violet.siamics.net>

>>>>> Rainer Weikusat <rweikusat@mssgmbh.com> writes:
>>>>> Mathias Korber <mathias@koerber.org> writes:

 >> I am looking for a module which can help translate human input for
 >> durations such as

 >> 3w4d20m10s into seconds (2161210).  Spaces inside the input should
 >> be ignored. If it can accept other formats, the better.

 > If you want to do this correctly, a start date is needed and the code
 > needs to calculate the 'target date' based on that.  Eg, '3m starting
 > on March 15th' would mean 'June 15th', a period of 61 days,

	I took it that the intervals the OP's interested in are weeks,
	days, hours (?), minutes, and seconds, and it's certainly
	possible (leap seconds issue put aside) to define these in the
	terms of seconds, irrespective of the starting point.

	Also to note is that the conventional "Unix time" system
	effectively accounts for leap seconds by "stretching" the plain
	seconds over certain interval.

	As for the "daylight savings time," it's indeed possible that
	"1 hour from 02:34, local time" would come to be either "02:34"
	or "04:34."  Which is one more reason to use UTC when one's
	interested in precise intervals specifically.

[...]

-- 
FSF associate member #7257


------------------------------

Date: Wed, 07 Aug 2013 13:57:14 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: translate human-readable time shorthand
Message-Id: <87pptpd5g5.fsf@sapphire.mobileactivedefense.com>

Ivan Shmakov <oneingray@gmail.com> writes:
>>>>>> Rainer Weikusat <rweikusat@mssgmbh.com> writes:
>>>>>> Mathias Korber <mathias@koerber.org> writes:
>
>  >> I am looking for a module which can help translate human input for
>  >> durations such as
>
>  >> 3w4d20m10s into seconds (2161210).  Spaces inside the input should
>  >> be ignored. If it can accept other formats, the better.
>
>  > If you want to do this correctly, a start date is needed and the code
>  > needs to calculate the 'target date' based on that.  Eg, '3m starting
>  > on March 15th' would mean 'June 15th', a period of 61 days,
>
> 	I took it that the intervals the OP's interested in are weeks,
> 	days, hours (?), minutes, and seconds, and it's certainly
> 	possible (leap seconds issue put aside) to define these in the
> 	terms of seconds, irrespective of the starting point.

It is certainly possible to define anything as anything. Eg, the
calculation becomes really simple when all of the involved units are
defined as '0 seconds': The result is then always 0, problem solved.
But this may not be what the people using the notation wanted to have.

> 	Also to note is that the conventional "Unix time" system
> 	effectively accounts for leap seconds by "stretching" the plain
> 	seconds over certain interval.

It doesn't. Provided the wallclock is managed by a 'sensibly working
NTP daemon' observing the NTP 'clock correctness principle' (and there
are loads and loads of people who think that the concept of 'time'
simply doesn't make sense and hence, using a mostly monotonic PRNG
with a sufficiently fine-grained resolution that humans are unlikely
to notice the problem easily ought to be 'good enough'), time
adjustments will be accomplished by changing the frequency of the
clock such that it converges towards 'the real time'. That's
unrelated to leap seconds which are inserted whenever 'the
timekeepers' think they have to and implemented such that the last
minute of the day is extended to have 61 instead of 60 seconds.


------------------------------

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 4009
***************************************


home help back first fref pref prev next nref lref last post