[22905] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5125 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 15 18:05:46 2003

Date: Sun, 15 Jun 2003 15:05:04 -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, 15 Jun 2003     Volume: 10 Number: 5125

Today's topics:
        about a very very simple alarm (Jason)
    Re: die and exception over-stringification <grazz@pobox.com>
        need help! (slash)
    Re: Reading Sendmail - mail files <me@privacy.net>
    Re: request in print<<test; (Andres Monroy-Hernandez)
    Re: Search through Array and evaluate the two <mgjv@tradingpost.com.au>
    Re: Tad McClellan (Graham Smith)
    Re: Tad McClellan <dha@panix.com>
        Time occasionally stops with Time::HiRes under windows. <cb750c@email.com>
    Re: Time occasionally stops with Time::HiRes under wind <me@privacy.net>
    Re: Time occasionally stops with Time::HiRes under wind <kalinabears@hdc.com.au>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 14 Jun 2003 22:55:32 -0700
From: gejun_1978@hotmail.com (Jason)
Subject: about a very very simple alarm
Message-Id: <cb54d77a.0306142155.31b60580@posting.google.com>

Hi Everyone,

I am new to Perl.  I want to write a simple alarm which will beep
every one hour, just to mention me to take a rest.  My simple script
is:

#!/usr/bin/perl -w
use strict;
my $interval = 3600;
while(1) {
    sleep($interval);
    print "time is up take a rest\n";
    print chr(7);  #bell the pc speaker
}


It works well if I don't close the console from which I run it.  But
if I close that console, the print statement won't beep, even though
the process is running.  Can anyone help me?

Jun Ge


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

Date: Sun, 15 Jun 2003 06:32:38 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: die and exception over-stringification
Message-Id: <aqUGa.570$ha2.343@nwrdny03.gnilink.net>

Joey Hess <joey@dragon.kitenet.net> wrote:
> The problem is that I'd rather only run my expensive operation 
> (it generates a _very_ expensive sort of call trace that's 
> specific to my environment) if the exception is actually displayed. 
> If something catches the exception, all that work would just be 
> thrown away.

Ah... the double stringification is fixed but /this/ still happens.

And I think you're right -- there's no reason why the object reference
should be stringified when you die() in an eval block.

-- 
Steve


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

Date: 14 Jun 2003 22:07:10 -0700
From: satishi@gwu.edu (slash)
Subject: need help!
Message-Id: <30fe9f1e.0306142107.7995223a@posting.google.com>

hi,
i am trying to use stacks to get the following done:

a
    c   
        e
        f
        g
    d
        e

my input is simply: 
a c
a c
a d
c a
c a
c g
c e
c e
c g
c g
c f
d a
d d
d d
d e 



can someone look at my useless code and tell me what I ought to do to
get the desired output. Am I even trying the right approach? Should I
use a different data structure?

undef $/;
my @lines = split /\W+/, <> ;
$root = shift @lines, $word[0];
my @array = $root;
foreach $word (@lines) {
 if ($word eq $root || $word eq $parent || $word eq $child) {
     shift @lines;
  } else
{
 push @array, $word;
   shift @lines;
     foreach $line (@lines) {
        if ($line ne $root || $line ne $parent || $line ne $child) {
            $child = shift @lines;
            push @array, $child;  
            push @child_array, $child;
            shift @lines;
            }
        else {
              shift @lines; 
         }
     }
}
}

i am a newbie to programming and there are lots of undesired things i
am getting here and would greatly appreciate if someone could point me
to the right direction.

thanks,
slash
can't seem to remedy.


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

Date: Sun, 15 Jun 2003 17:33:35 +1200
From: "Tintin" <me@privacy.net>
Subject: Re: Reading Sendmail - mail files
Message-Id: <bch0cd$it351$1@ID-172104.news.dfncis.de>


"rjh" <ccsc3618@bigpond.net.au> wrote in message
news:MaSGa.5620$GU5.87114@news-server.bigpond.net.au...
> Hi, Has anyone had experience coding a perl script that can manipulate
unix
> mail files.
>
> IE: The sendmail /var/spool/mail/USER mail file.
>
> My requirement.
> Logs are emailed to an account on my linux (RedHat) server.
> Currently, i have to login, open mail, manually save each message out to a
> file and then run perl scripts over to saved files to extract the data i
> need.
>
> Surely i can perl the mail file and read the from / date mail headers and
> then save the email to file , then delete the email from
> /var/spool/mail/USER.
>
>
> Any modules out there that make this job easy.  Any techniques / info
> welcomed.

Plenty of modules.

 Look at http://search.cpan.org/search?query=mbox&mode=all and take your
pick.




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

Date: 14 Jun 2003 23:23:55 -0700
From: andres@monroy.com (Andres Monroy-Hernandez)
Subject: Re: request in print<<test;
Message-Id: <3591b31a.0306142223.656b5eeb@posting.google.com>

> I use CGI.pm and do a request like $q->param('test') and I need to put it in
> 
> print<<example;
> some text maby <br> and the $q->param('test')
> example
> 
> The problem is that it only take $q->param and skip ('test') can I put that
> in allso or must I buffer it to example $test = $q->param('test')? The code
> is so mutch better if I can skip that.
> thx

Try this:

print<<example;
some text maby <br> and the ${\($q->param('test'))}
example


Regards,
Andrés Monroy


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

Date: Sun, 15 Jun 2003 13:50:17 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Search through Array and evaluate the two
Message-Id: <slrnbenr7p.rlm.mgjv@martien.heliotrope.home>

On 14 Jun 2003 16:16:59 GMT,
	James E Keenan <jkeen@concentric.net> wrote:
> 
> "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
> news:slrnbeiint.luq.mgjv@verbruggen.comdyn.com.au...

>> If you have to deal specifically with undefined values in @barcodes,
>> you will have to deal with that. How you deal with it depends on what
>> that undefined value means.
>>
>> The following three methods all end up with the same hash contents:
>>
> 
> Let's modify the original array assignment to include an 'undef', then test:
> 
> my @barcodes = ( 'alpha', 'beta', 'gamma', 'delta', 'alpha',
>     'epsilon', 'beta', 'zeta', 'eta', 'theta', 'gamma', undef );
> 
>     sub showhash {
>         my $ref = shift;
>         print "\nTest\n";
>         foreach (sort keys %$ref) {
>             print "Element:  $_\tLast seen at index:  ${$ref}{$_}\n";
>         }
>     }
> 
> 
>> my %seenlast1;
>>
>> for (my $i=0; $i<=$#barcodes; $i++) {
>>     if (defined $seenlast1{$barcodes[$i]}) {
>> $seenlast1{$barcodes[$i]} = $i if $i > $seenlast1{$barcodes[$i]};
>>     } else {
>> $seenlast1{$barcodes[$i]} = $i;
>>     }
>> }
> 
> showhash(\%seenlast1); runs without warnings re uninitialized values

showhash() might run without warnings, but the quorted code itself
doesn't. Why does it matter that you get warnings with one bit of code,
but not with another?

Again: If you're worried about undefined values in @barcodes, you should
be dealing with them when creating the hash, and you're not. All of the
three hash population methods in this post will use an undefined value
as a hash key. In all three cases that will generate a warning, although
the warnings do differ. In all
three cases will the resulting hash be exactly the same.

>> my %seenlast2;
>>
>> for (my $i=0; $i < @barcodes; $i++) {
>>     $seenlast2{$barcodes[$i]} = $i;
>> }
>>
> 
> showhash(\%seenlast2); warns about uninitialized values

No, it doesn't. %seenlast2 is exactly identical to %seenlast1. The
warnings are there, but not in the showhash() call. The warnings are
generated by the lines _before_ the call to showhash.

>> my %seenlast3;
>> @seenlast3{@barcodes} = (0 .. $#barcodes);

> showhash(\%seenlast3); warns about uninitialized values

Same here for %seenlast3. No warnings in the call to showhash.

> Avoiding uninitialized values was why I used 'defined' rather than 'exists'.

You're not testing for undefined values in the original array. You are
testing whether $seenlast1{$barcodes[$i]} is undefined. That can be
undefined for several reasons, which all have to do with the hash, not
with the original array. Did you mean to do defined($barcodes[$i])
instead then?

> If you go back to the OP, you'll see that he was populating the array via
> calls to a database.  I did not have a way of quickly reproducing the whole
> of his code on my system, so I wanted to exclude the possibility that his
> code might return 'undef' values.  That's why I tested for definedness in my
> code.

Ok, but in that case, you've got a bug, since you're testing whether
there is an undefined value stored at $seenlast{$barcodes[$i]}, which is
not the same as testing whether $barcodes[$i] is defined.

Martien
-- 
                        | 
Martien Verbruggen      | The Second Law of Thermodenial: In any closed
                        | mind the quantity of ignorance remains
                        | constant or increases.


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

Date: 14 Jun 2003 23:23:37 -0700
From: grehom@ntlworld.com (Graham Smith)
Subject: Re: Tad McClellan
Message-Id: <98eb7f13.0306142223.36bc70ea@posting.google.com>

I apologize Tad, I've done what I should have done in the first place
and studied all his recent postings - what I should have said was...
oh I wish I'd said nothing.

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnben6b1.8l3.tadmc@magna.augustmail.com>...
> Julia deSilva <jds@trumpetweb.co.uk> wrote:
> 
> > firing thunderbolts
> > down to earth every-so-often
> 
> 
> There are some who call me ...
> 
> 
>  ...
> 
> 
>  ... Tim?


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

Date: Sun, 15 Jun 2003 07:35:17 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: Tad McClellan
Message-Id: <slrnbeo8dl.hag.dha@panix2.panix.com>

In article <slrnben6b1.8l3.tadmc@magna.augustmail.com>, Tad McClellan wrote:
> Julia deSilva <jds@trumpetweb.co.uk> wrote:
> 
>> firing thunderbolts
>> down to earth every-so-often
> 
> 
> There are some who call me ...
> 
> 
>  ...
> 
> 
>  ... Tim?

You realize I'm going to start calling you that now, right?  :-)

dha
-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"Dir-ty deeds...DONE TO SHEEP!"
Heh heh...AC/DC, eat yer heart out.
    - Mary Roth


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

Date: Sun, 15 Jun 2003 02:04:21 -0400
From: "Scott G." <cb750c@email.com>
To: edh@einstein.unh.edu
Subject: Time occasionally stops with Time::HiRes under windows.
Message-Id: <pan.2003.06.15.06.04.21.357452@email.com>

Hi all, I've got a question about doing cross platform development with
Time::HiRes. A few lines of code are worth a thousand words, right? :)

The code:

#!/usr/bin/perl
                                                                                
use strict;
use warnings;
use Time::HiRes;
use POSIX;
                                                                                
my $now = Time::HiRes::time();
my ($i, $oldtime);
                                                                                
for ($i = 0; $i < 100; $i++) {
    printf("It is now %f\n", $now);
                                                                                
    wait_next_second();
    $oldtime = $now;
    $now = Time::HiRes::time();
    if ($oldtime == $now) {
        print "Time has stopped! $now\n";
    }
}

# Sleep until the next whole second is reached. 
sub wait_next_second {
    my $time = Time::HiRes::time();
    my $timeleft = ceil($time) - $time;
                                                                                
    if ($timeleft > 0) {
        Time::HiRes::sleep($timeleft);
    }
    elsif ($timeleft == 0) {
        print "Time left is exactly zero.\n";
    }
    else {
        print "Time left was negative?\n";
    }
}


The test machines:
- RedHat 9, perl 5.8
- Windows XP Home, ActiveState Perl 5.8 build 806

The symptoms:
- Script runs as expected on Linux platform, time progresses normally as
it is printed out 100 times.

- Script runs haphazardly under Windows, generally starts to work right
and then randomly starts spewing a few dozen "Time has stopped!" messages
at a time before behaving normally again for a bit, then misbehaving
again, etc.

Can anyone explain why this is happening, and how to work around it?

Many thanks,

Scott 


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

Date: Sun, 15 Jun 2003 18:23:47 +1200
From: "Tintin" <me@privacy.net>
Subject: Re: Time occasionally stops with Time::HiRes under windows.
Message-Id: <bch3ah$j0evi$1@ID-172104.news.dfncis.de>


"Scott G." <cb750c@email.com> wrote in message
news:pan.2003.06.15.06.04.21.357452@email.com...
> Hi all, I've got a question about doing cross platform development with
> Time::HiRes. A few lines of code are worth a thousand words, right? :)
>
> The code:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> use Time::HiRes;
> use POSIX;
>
> my $now = Time::HiRes::time();
> my ($i, $oldtime);
>
> for ($i = 0; $i < 100; $i++) {
>     printf("It is now %f\n", $now);
>
>     wait_next_second();
>     $oldtime = $now;
>     $now = Time::HiRes::time();
>     if ($oldtime == $now) {
>         print "Time has stopped! $now\n";
>     }
> }
>
> # Sleep until the next whole second is reached.
> sub wait_next_second {
>     my $time = Time::HiRes::time();
>     my $timeleft = ceil($time) - $time;
>
>     if ($timeleft > 0) {
>         Time::HiRes::sleep($timeleft);
>     }
>     elsif ($timeleft == 0) {
>         print "Time left is exactly zero.\n";
>     }
>     else {
>         print "Time left was negative?\n";
>     }
> }
>
>
> The test machines:
> - RedHat 9, perl 5.8
> - Windows XP Home, ActiveState Perl 5.8 build 806
>
> The symptoms:
> - Script runs as expected on Linux platform, time progresses normally as
> it is printed out 100 times.
>
> - Script runs haphazardly under Windows, generally starts to work right
> and then randomly starts spewing a few dozen "Time has stopped!" messages
> at a time before behaving normally again for a bit, then misbehaving
> again, etc.
>
> Can anyone explain why this is happening, and how to work around it?

The problem with Windows is that Microsoft has designed the anti-time
feature.  This feature is designed to ensure Windows will never be current
and will require constant patches and upgrades to bring it to the current
time.




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

Date: Sun, 15 Jun 2003 16:55:11 +1000
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: Time occasionally stops with Time::HiRes under windows.
Message-Id: <3eec1978$0$20546@echo-01.iinet.net.au>


"Scott G." <cb750c@email.com> wrote in message
news:pan.2003.06.15.06.04.21.357452@email.com...
> Hi all, I've got a question about doing cross platform development with
> Time::HiRes. A few lines of code are worth a thousand words, right? :)
>
> The code:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> use Time::HiRes;
> use POSIX;
>
> my $now = Time::HiRes::time();
> my ($i, $oldtime);
>
> for ($i = 0; $i < 100; $i++) {
>     printf("It is now %f\n", $now);
>
>     wait_next_second();
>     $oldtime = $now;
>     $now = Time::HiRes::time();
>     if ($oldtime == $now) {
>         print "Time has stopped! $now\n";
>     }
> }
>
> # Sleep until the next whole second is reached.
> sub wait_next_second {
>     my $time = Time::HiRes::time();
>     my $timeleft = ceil($time) - $time;
>
>     if ($timeleft > 0) {
           print "Sleeping for $timeleft seconds\n";
>         Time::HiRes::sleep($timeleft);
>     }
>     elsif ($timeleft == 0) {
>         print "Time left is exactly zero.\n";
>     }
>     else {
>         print "Time left was negative?\n";
>     }
> }
>

I've inserted a line of code (above). When you run the script now you'll see
that the "Time has stopped!" message occurs when $timeleft is something like
1.50203704833984e-005.

Looks like, on windows at least, you sometimes don't sleep for quite long
enough - probably due to the granularity of time measurement. I'm
speculating that you'll then get multiple iterations of wait_next_second()
and "Time has stopped" messages because
Time::HiRes::sleep(1.50203704833984e-005) is the same as
Time::HiRes::sleep(0).

Would have thought you could get the same on other systems.

Cheers,
Rob





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

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


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