[23368] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5587 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 29 21:05:46 2003

Date: Mon, 29 Sep 2003 18:05:12 -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           Mon, 29 Sep 2003     Volume: 10 Number: 5587

Today's topics:
    Re: Am I on the right track - timezones <ddunham@redwood.taos.com>
    Re: Am I on the right track - timezones (Jon)
    Re: Artificial intelligence (AI) has been solved <dmagda+trace030927@ee.ryerson.ca>
        Endless Loop (trying for...) (Brian)
    Re: Endless Loop (trying for...) <mhunter@uclink.berkeley.edu>
    Re: Endless Loop (trying for...) <bharnish@technologist.com>
    Re: Endless Loop (trying for...) <ddunham@redwood.taos.com>
    Re: Endless Loop (trying for...) <kuujinbo@hotmail.com>
        get messages from background task to log file (start-st <telsi@web.de>
    Re: get messages from background task to log file (star (David Efflandt)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 29 Sep 2003 21:43:09 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Am I on the right track - timezones
Message-Id: <NH1eb.10396$3F1.5229@newssvr25.news.prodigy.com>

Jon <jon18_uk2002@yahoo.co.uk> wrote:

> I am trying to take a date (day/month/year) and time (hour:min) from
> the user, and also a timezone which that date/time is based on.  I
> then need to pull all logs out of a database which happens on that
> supplied date and time.

> The log stores everything by its timestamp, which I take from time(). 
> So all the timestamps should be based in UTC time.  So first step I
> need to do is take the supplied date/time and turn it into a UTC
> timestamp.

> I do that by setting the $ENV{TZ} to the timezone and then use
> timegm(), I remembered to take away -1 from the month.

Uhh, no.  If you want to feed in a timezone-offset time, then you want
timelocal.  

What you get out of either one isn't really "UTC timestamps", it's
"seconds since the epoch".  The gm vs local specifies the *input*.  I
think your statement of "timestamps should be based in UTC time" is
confusing you.

Just pretend the timestamps are opaque and have nothing to do with GMT
or UTC or anything.  You set the TZ and create the stamps with
timelocal, and you set the TZ and read the stamps with localtime.

> $ENV{TZ} = ':/usr/share/zoneinfo/Europe/Paris';
> $localseconds = timegm(27,11,10,15,8,2003);
> print "$localseconds\n";

> (11 minutes past 10am, and 27 seconds on the 15th August 2003)

> $localseconds is 1063620687.

> $ENV{TZ} = ':/usr/share/zoneinfo/Europe/Paris';
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
> localtime('1063620687');

Expecting to have timegm and localtime be each others reverse does not
make sense to me.

timegm/localgm  timelocal/localtime.

-- 
Darren Dunham                                           ddunham@taos.com
Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >


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

Date: 29 Sep 2003 18:03:58 -0700
From: jon18_uk2002@yahoo.co.uk (Jon)
Subject: Re: Am I on the right track - timezones
Message-Id: <83bd902f.0309291703.7fe0700e@posting.google.com>

"Mothra" <mothra@nowhereatall.com> wrote in message news:<3f76f5ff$1@usenet.ugs.com>...
> [snipped]
> Please take a look at the DateTime project.
>  http://datetime.perl.org/
> 
> > Thank you in advance for any help,
> >
> > Jon.
> 
> Hope this helps
> 
> Mothra

Thanks for that, DateTime seems just what I need.  However, I noticed
a possible reason why stuff I was doing was not working.  When I set
the TZ to the timezone, any other changes I make do not take effect.

$ENV{TZ} = ':/usr/share/zoneinfo/Europe/London';

$time = time();

($sec,$min,$hour,$day,$mon,$this_year,$wday,$yday,$isdst) =
localtime($time);
print "$hour:$min\n";

$ENV{TZ} = ':/usr/share/zoneinfo/Europe/Paris';

($sec,$min,$hour,$day,$mon,$this_year,$wday,$yday,$isdst) =
localtime($time);
print "$hour:$min\n";

So this should return 2 times, within an hour of each other, however
it returns the same time.

1:57
1:57

So I done some more digging, and run strace on the script, it turns
out it only opens the first zoneinfo file.  I tried the same script on
another server, and it worked correctly.  The one it failed on is
running Perl v5.8.0, on Linux kernel 2.4.20.

The working servers run a older version of Perl and of the kernel.  I
did read about localtime caching the timezone, but didn't think that
happen now days.

Jon.


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

Date: 29 Sep 2003 18:42:01 -0400
From: David Magda <dmagda+trace030927@ee.ryerson.ca>
Subject: Re: Artificial intelligence (AI) has been solved
Message-Id: <86ekxz6wue.fsf@number6.magda.ca>

Lucius Chiaraviglio <luciusone@chapter.net> writes:

> On Thu, 04 Sep 2003 11:17:56 +0000, Anno Siegel wrote:
> > Artificial intelligence rests on the hope that eventually the computer
> > will do something only humans can do.  Software engineering rests on the
> > hope that eventually the computer will do something, anything, please?
> 
> 	I assume you mean other than crash?  :-)

Boycott artificial intelligence! Demand natural intelligence!

-- 
David Magda <dmagda at ee.ryerson.ca>, http://www.magda.ca/
Because the innovator has for enemies all those who have done well under
the old conditions, and lukewarm defenders in those who may do well 
under the new. -- Niccolo Machiavelli, _The Prince_, Chapter VI


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

Date: 29 Sep 2003 15:07:30 -0700
From: BChirhart@fnni.com (Brian)
Subject: Endless Loop (trying for...)
Message-Id: <9d13498b.0309291407.6e5374b1@posting.google.com>

Shouldn't - 

my @a;
my $y = 1;
push (@a, $y);
foreach my $x (0..$#a) {
	print "array = @a\n";
	$y++;
	push (@a, $y);
	}

result in an endless loop?  And if not (I can't get it to) how do I
create an endless loop like that above?

I want to parse through an array, but change the size of the array at
the same time.  Don't worry, actual program will have checks and
balances so it does not run till the end of time.


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

Date: Mon, 29 Sep 2003 22:14:31 +0000 (UTC)
From: Mike Hunter <mhunter@uclink.berkeley.edu>
Subject: Re: Endless Loop (trying for...)
Message-Id: <slrnbnhbii.17h.mhunter@celeste.net.berkeley.edu>

On 29 Sep 2003 15:07:30 -0700, Brian wrote:
>  Shouldn't - 
>  
>  my @a;
>  my $y = 1;
>  push (@a, $y);
>  foreach my $x (0..$#a) {
>  	print "array = @a\n";
>  	$y++;
>  	push (@a, $y);
>  	}
>  
>  result in an endless loop?  And if not (I can't get it to) how do I
>  create an endless loop like that above?
>  
>  I want to parse through an array, but change the size of the array at
>  the same time.  Don't worry, actual program will have checks and
>  balances so it does not run till the end of time.

My uninformed guess is that (0..$#a) is evaluated once upon startup.


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

Date: Mon, 29 Sep 2003 22:22:12 GMT
From: Brian Harnish <bharnish@technologist.com>
Subject: Re: Endless Loop (trying for...)
Message-Id: <pan.2003.09.29.22.22.18.575110@technologist.com>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

On Mon, 29 Sep 2003 15:07:30 -0700, Brian wrote:

> Shouldn't - 
> 
> my @a;
> my $y = 1;
> push (@a, $y);
> foreach my $x (0..$#a) {
> 	print "array = @a\n";
> 	$y++;
> 	push (@a, $y);
> 	}
> 
> result in an endless loop?  And if not (I can't get it to) how do I
> create an endless loop like that above?

No, 0..$#a is only evaluated at the beginning of the loop. You would want
to use the c-style for syntax, where the condition is evaluated each time.

for(my $x = 0; $x <= $#a; $x++) {
	push(@a,$y);
}

 - Brian
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/eLCXiK/rA3tCpFYRAvn7AKDaIAsuOvEXHGWgNPn3yAt69LtI3ACgnujD
FR0hQ5DleXV0ZpqUOM7Oaj4=
=vVby
-----END PGP SIGNATURE-----



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

Date: Mon, 29 Sep 2003 23:13:11 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Endless Loop (trying for...)
Message-Id: <b03eb.10413$jq2.1842@newssvr25.news.prodigy.com>

Brian <BChirhart@fnni.com> wrote:
> Shouldn't - 

> my @a;
> my $y = 1;
> push (@a, $y);
> foreach my $x (0..$#a) {
> 	print "array = @a\n";
> 	$y++;
> 	push (@a, $y);
> 	}

> result in an endless loop?  And if not (I can't get it to) how do I
> create an endless loop like that above?

Well, by using $#a, you're giving a specific set of indexes (0 and
whatever $#a is) to operate on.

If you want to operate on an array, operate on an array.  This is how I
would have done it in the first place.  Don't mess with indexes if you
don't want to mess with indexes...

my $y = 1;
my @a = ($y);
foreach my $x (@a)
{
  print "array = @a\n";
  print "index variable= $x\n";
  $y++;
  push (@a, $y);
}

-- 
Darren Dunham                                           ddunham@taos.com
Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >


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

Date: Tue, 30 Sep 2003 09:18:28 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: Endless Loop (trying for...)
Message-Id: <blai7v$si1$1@pin3.tky.plala.or.jp>

Brian wrote:

> Shouldn't - 
> 
> my @a;
> my $y = 1;
> push (@a, $y);
> foreach my $x (0..$#a) {
> 	print "array = @a\n";
> 	$y++;
> 	push (@a, $y);
> 	}
> 
> result in an endless loop?  And if not (I can't get it to) how do I
> create an endless loop like that above?
> 
> I want to parse through an array, but change the size of the array at
> the same time.  Don't worry, actual program will have checks and
> balances so it does not run till the end of time.

You can use a while loop:

while (@a) {
   print "@a\n";
   parse_sub($a[$y]);	# your array parsing sub
   push @a, $y++;
   last if $y > 5;	# your end condition
}



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

Date: Mon, 29 Sep 2003 23:51:22 +0200
From: "Grischa Schuering" <telsi@web.de>
Subject: get messages from background task to log file (start-stop-daemon with perl script stderr)
Message-Id: <bla9gr$j3q$06$1@news.t-online.com>

Hello,

I have a perl daemon running using the start-stop-daemon in background mode.
Now I would like to get the mnessages, that were originally send on STDIN,
STDOUT, STDERR to a file.

Using start-stop-daemon --exec $DAEMON --background >$2 file.log is not
working. No wonder, sonce a backround task should not send any information
to STDIN and so on.

What is the correct command to get the mesages to file or syslog
(whatever)???





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

Date: Mon, 29 Sep 2003 23:53:13 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: get messages from background task to log file (start-stop-daemon with perl script stderr)
Message-Id: <slrnbnhhf9.qbs.efflandt@typhoon.xnet.com>

On Mon, 29 Sep 2003 23:51:22 +0200, Grischa Schuering <telsi@web.de> wrote:
> Hello,
> 
> I have a perl daemon running using the start-stop-daemon in background mode.
> Now I would like to get the mnessages, that were originally send on STDIN,
> STDOUT, STDERR to a file.
> 
> Using start-stop-daemon --exec $DAEMON --background >$2 file.log is not
> working. No wonder, sonce a backround task should not send any information
> to STDIN and so on.
> 
> What is the correct command to get the mesages to file or syslog
> (whatever)???

Look for SyS::Syslog module.

Working example:

#!/usr/bin/perl -w
# Name of this script
if ($0 =~ m|/([^/]+)$|) { $id = $1; } else { $id = $0; }
use Sys::Syslog qw(:DEFAULT setlogsock);
setlogsock 'unix' || die "Can't setlogsock";
sub mylog {
    my $msg = shift;
    chomp $msg;	# if needed
    syslog('info',"$id\[$$]:$msg"); closelog();
}
mylog("I'm running");


The script was called 'logme', result in syslog:

Sep 29 18:48:27 efflandt logme[31707]: I'm running

-- 
David Efflandt - All spam ignored  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

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.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 5587
***************************************


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