Re: Date::manip query

2007-12-19 Thread pauld
im sorting it on a key of the hash
my @daylistsorted = sort { $$a{'START_DS'} = $$b{'START_DS'} }
@daylist;
 generates a
Argument 2007:09:30 13:41 isn't numeric in numeric comparison (=)
at ./518573

error

my @daylistsorted = sort { $$a{'START'} = $$b{'START'} } @daylist;

works


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Date::manip query

2007-12-19 Thread Tom Phoenix
On 12/19/07, pauld [EMAIL PROTECTED] wrote:

 im sorting it on a key of the hash
 my @daylistsorted = sort { $$a{'START_DS'} = $$b{'START_DS'} }
 @daylist;
  generates a
 Argument 2007:09:30 13:41 isn't numeric in numeric comparison (=)
 at ./518573

Have you tried using a string comparison when you want to compare
strings? In Perl, that's the cmp operator.

http://perldoc.perl.org/perlop.html

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Date::manip query

2007-12-19 Thread Gunnar Hjalmarsson

pauld wrote:

Gunnar Hjalmarsson wrote:

pauld wrote:

im using Date::Manip to convert dates  and times eg  2007:08:02 12:23
to allow me to sort them,


Why are you doing that?

C:\hometype test.pl
@dates = ( '2007:08:02 12:23', '2007:10:21 04:40',
  '2007:06:05 16:08', '2007:09:11 22:20', );
print $_\n for sort @dates;

C:\hometest.pl
2007:06:05 16:08
2007:08:02 12:23
2007:09:11 22:20
2007:10:21 04:40


im sorting it on a key of the hash
my @daylistsorted = sort { $$a{'START_DS'} = $$b{'START_DS'} }
@daylist;
 generates a
Argument 2007:09:30 13:41 isn't numeric in numeric comparison (=)
at ./518573


My point is that the format :mm:dd hh:mm is sortable without 
conversion. However, you need to sort lexically, i.e. use the cmp 
operator instead of the = operator.


--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Date::manip query

2007-12-18 Thread Rob Dixon

pauld wrote:


im importing data from an excel spreadsheet into an array of hashes.
the date is initially converted using Date::Format::Excel.

for this bit

{START} = unix start time .{START_DS} = string that I use to convert
to unixtime with

my $var=0;my [EMAIL PROTECTED];
while ($var$va_length)
{
print ${$daylistsorted[$var]}{TH} ;
print   'from ';
print ${$daylistsorted[$var]}{START};
print ' to '.${$daylistsorted[$var]}{END_DS};
printduration  ;print   int((${$daylistsorted[$var]}{END}-$
{$daylistsorted[$var]}{START})/60);

if (exists(  ${$daylistsorted[$var+1]}{TH}  )   )
 {
print \tinterval to next start ; print int ((${$daylistsorted[$var
+1]}{START}-${$daylistsorted[$var]}{END})/60);print  \n;
 }
$var++;
}}

Sat  04-08-2007
=
1 from 1186220100 to 2007:08:04 10:33   duration  58 interval to next
start 34
4 from 1186225620 to 2007:08:04 13:29   duration  142  interval to
next start 26

and when i change it to
#print ${$daylistsorted[$var]}{START};
print UnixDate(${$daylistsorted[$var]}{START}, '%Y:%m:%d %H:%M');

 I get this

Sat  04-08-2007
=
 1 from  to 2007:08:04 10:33   duration  58   interval to next start
34
 4 from  to 2007:08:04 13:29   duration  142  interval to next start
26


with both dates as strings


Sat  04-08-2007
=
1 from 2007:08:04 09:35 to 2007:08:04 10:33   duration  58   interval
to next start 34
4 from 2007:08:04 11:07 to 2007:08:04 13:29   duration  142  interval
to next start 26


Your START and END fields appear to be seconds since epoch, whereas the
END_DS field is in the form '%Y:%m:%d %H:%M' as you described in your
earlier post. Neither of these are anything to do with the Date::Manip
module and consequently the answers you have had were irrelevant.

To display a time value such as this in a custom format you can use the
strftime() function from the POSIX module. The program below exemplifies
this.

However, unless I am misunderstanding you you already have the START
time as a string in START_DS. Isn't this sufficient?

HTH,

Rob



use strict;
use warnings;

use POSIX qw(strftime);

my $date_time = 1186220100;

print strftime('%Y:%m:%d %H:%M', localtime($date_time));

**OUTPUT**

2007:08:04 10:35

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Date::manip query

2007-12-18 Thread pauld
the END_DS field is the date  field that I want  - but as I couldnt
get it back from the seconds  since epoch field I included it.
IMHO it would be tideir to just use the (numerical) date-seconds and
convert it back as necessary . i used the Date::Manip function
Date_SecsSince1970($m,$d,$y,$h,$mn,$s); to get the date time  into a
format  I can sort it by. i was wanting to use Date::manip to extract
the bits i want ( HH:MM) for the final display. i can do it by
splitting the text formatted  value (START_DS)  but i thought it would
be neater ( and i'd learnt something ) by doing it using the module


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Date::manip query

2007-12-18 Thread Gunnar Hjalmarsson

pauld wrote:

im using Date::Manip to convert dates  and times eg  2007:08:02 12:23
to allow me to sort them,


Why are you doing that?

C:\hometype test.pl
@dates = ( '2007:08:02 12:23', '2007:10:21 04:40',
  '2007:06:05 16:08', '2007:09:11 22:20', );
print $_\n for sort @dates;

C:\hometest.pl
2007:06:05 16:08
2007:08:02 12:23
2007:09:11 22:20
2007:10:21 04:40

C:\home

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Date::manip query

2007-12-17 Thread pauld
im importing data from an excel spreadsheet into an array of hashes.
the date is initially converted using Date::Format::Excel.

for this bit

{START} = unix start time .{START_DS} = string that I use to convert
to unixtime with

my $var=0;my [EMAIL PROTECTED];
while ($var$va_length)
{
print ${$daylistsorted[$var]}{TH} ;
print   'from ';
print ${$daylistsorted[$var]}{START};
print ' to '.${$daylistsorted[$var]}{END_DS};
printduration  ;print   int((${$daylistsorted[$var]}{END}-$
{$daylistsorted[$var]}{START})/60);

if (exists(  ${$daylistsorted[$var+1]}{TH}  )   )
 {
print \tinterval to next start ; print int ((${$daylistsorted[$var
+1]}{START}-${$daylistsorted[$var]}{END})/60);print  \n;
 }
$var++;
}}

Sat  04-08-2007
=
1 from 1186220100 to 2007:08:04 10:33   duration  58 interval to next
start 34
4 from 1186225620 to 2007:08:04 13:29   duration  142  interval to
next start 26

and when i change it to
#print ${$daylistsorted[$var]}{START};
print UnixDate(${$daylistsorted[$var]}{START}, '%Y:%m:%d %H:%M');

 I get this

Sat  04-08-2007
=
 1 from  to 2007:08:04 10:33   duration  58   interval to next start
34
 4 from  to 2007:08:04 13:29   duration  142  interval to next start
26


with both dates as strings


Sat  04-08-2007
=
1 from 2007:08:04 09:35 to 2007:08:04 10:33   duration  58   interval
to next start 34
4 from 2007:08:04 11:07 to 2007:08:04 13:29   duration  142  interval
to next start 26


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Date::manip query

2007-12-17 Thread davidfilmer
On Dec 17, 3:22 am, [EMAIL PROTECTED] (Pauld) wrote:
 my $var=0;my [EMAIL PROTECTED];
 while ($var$va_length)
 {
 print ${$daylistsorted[$var]}{TH} ;
 print   'from ';
 print ${$daylistsorted[$var]}{START};
 print ' to '.${$daylistsorted[$var]}{END_DS};
 printduration  ;print   int((${$daylistsorted[$var]}{END}-$
 {$daylistsorted[$var]}{START})/60);

It's unusual in Perl to need to access an array element by its index
number.  This is one of those times, though, when it is useful to use
an index because you need to peek ahead at the next item in the
array.  But you only need the index for the next item, not for the
current item, so you can clean up things a bit with something like
this (untested, and posted without much effort to parse or understand
the objective of the code, and using printf instead of a bunch of
concat'ed strings):

   my $index = 0;
   foreach my $day( @daylistsorted ) {
  printf (
 %s from $s to %s duration %s %s\n,
$day{'TH'},
UnixDate($day{'START'},  '%Y:%m:%d %H:%M'),
UnixDate($day{'END_DS'}, '%Y:%m:%d %H:%M'),
int(($day{END} - $day{START})/60);
(exists(  ${$daylistsorted[$index+1]}{TH} ) )
   ? \tinterval to next start 
 .int (( ${$daylistsorted[$index+1]}{START}
-$day{END} )/60)
   : ''
  );
  $index++;
   }


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Date::manip query

2007-12-17 Thread John W . Krahn
On Monday 17 December 2007 15:40, [EMAIL PROTECTED] wrote:

 On Dec 17, 3:22 am, [EMAIL PROTECTED] (Pauld) wrote:
 
  my $var=0;my [EMAIL PROTECTED];
  while ($var$va_length)
  {
  print ${$daylistsorted[$var]}{TH} ;
  print   'from ';
  print ${$daylistsorted[$var]}{START};
  print ' to '.${$daylistsorted[$var]}{END_DS};
  printduration  ;print   int((${$daylistsorted[$var]}{END}-$
  {$daylistsorted[$var]}{START})/60);

 It's unusual in Perl to need to access an array element by its index
 number.  This is one of those times, though, when it is useful to use
 an index because you need to peek ahead at the next item in the
 array.  But you only need the index for the next item, not for the
 current item, so you can clean up things a bit with something like
 this (untested, and posted without much effort to parse or understand
 the objective of the code, and using printf instead of a bunch of
 concat'ed strings):

my $index = 0;
foreach my $day( @daylistsorted ) {

The way it is *usually* done is:

foreach my $index ( 0 .. $#daylistsorted ) {


   printf (
  %s from $s to %s duration %s %s\n,
 $day{'TH'},

An array element can hold a hash reference but not a hash itself:

  $day-{ TH },


 UnixDate($day{'START'},  '%Y:%m:%d %H:%M'),

   $day-{ START }


 UnixDate($day{'END_DS'}, '%Y:%m:%d %H:%M'),

   $day-{ END_DS }


 int(($day{END} - $day{START})/60);

   $day-{ END } - $day-{ START }


 (exists(  ${$daylistsorted[$index+1]}{TH} ) )
? \tinterval to next start 
  .int (( ${$daylistsorted[$index+1]}{START}
 -$day{END} )/60)

   $day-{ END }



: ''

   );
   $index++;
}


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Date::manip query

2007-12-17 Thread Chas. Owens
On Dec 18, 2007 1:05 AM, John W. Krahn [EMAIL PROTECTED] wrote:
snip
printf (
   %s from $s to %s duration %s %s\n,
snip

You missed the usage of $s instead of %s.  I always get bitten by that.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Date::manip query

2007-12-16 Thread pauld
im using Date::Manip to convert dates  and times eg  2007:08:02 12:23
to allow me to sort them, which it does .
but I cant see how to get the number back into a human -readable
format

print scalar localtime($var{STARTTIME}); prints the long string . is
there a better way to get just the bits I want  , or do I have to
parse the string I get from print scalar localtime  output ?




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Date::manip query

2007-12-16 Thread John W . Krahn
On Sunday 16 December 2007 04:31, pauld wrote:

 im using Date::Manip to convert dates  and times eg  2007:08:02 12:23
 to allow me to sort them, which it does .
 but I cant see how to get the number back into a human -readable
 format

Use the UnixDate() function that comes with Date::Manip.


 print scalar localtime($var{STARTTIME}); prints the long string . is
 there a better way to get just the bits I want  , or do I have to
 parse the string I get from print scalar localtime  output ?

Use localtime in list context instead.

perldoc -f localtime



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Date::manip query

2007-12-16 Thread Rob Dixon

pauld wrote:


im using Date::Manip to convert dates  and times eg  2007:08:02 12:23
to allow me to sort them, which it does .
but I cant see how to get the number back into a human -readable
format

print scalar localtime($var{STARTTIME}); prints the long string . is
there a better way to get just the bits I want  , or do I have to
parse the string I get from print scalar localtime  output ?


Have you read the documentation for Date::Manip?

The UnixDate() function will do what you want. Something like

  print UnixDate($date, '%Y:%m:%d %H:%M');

for instance, which will reproduce the date in the format you have
shown.

HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/