[30125] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1368 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 18 15:08:31 2008

Date: Mon, 17 Mar 2008 13:09:09 -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, 17 Mar 2008     Volume: 11 Number: 1368

Today's topics:
        cannot post message to perl beginners <john1949@yahoo.com>
        decrease MAC <jameslockie@mail.com>
    Re: FAQ 5.39 Why do I get weird spaces when I print an  <tzz@lifelogs.com>
    Re: HTML parsing <mirod@xmltwig.com>
    Re: Inside-out objects are slow! (or how to accelerate  xhoster@gmail.com
    Re: Inside-out objects are slow! (or how to accelerate  <abigail@abigail.be>
    Re: Inside-out objects are slow! (or how to accelerate  <koszalekopalek@interia.pl>
    Re: Inside-out objects are slow! (or how to accelerate  <koszalekopalek@interia.pl>
    Re: Inside-out objects are slow! (or how to accelerate  xhoster@gmail.com
    Re: Inside-out objects are slow! (or how to accelerate  <koszalekopalek@interia.pl>
    Re: Inside-out objects are slow! (or how to accelerate  <koszalekopalek@interia.pl>
    Re: Inside-out objects are slow! (or how to accelerate  xhoster@gmail.com
    Re: Inside-out objects are slow! (or how to accelerate  <joost@zeekat.nl>
        test <john1949@yahoo.com>
        trying to execute 'at now + 2 minutes... <mmccaws@comcast.net>
    Re: trying to execute 'at now + 2 minutes... (Randal L. Schwartz)
    Re: trying to execute 'at now + 2 minutes... sandy_saydakov@yahoo.com
    Re: trying to execute 'at now + 2 minutes... xhoster@gmail.com
    Re: trying to execute 'at now + 2 minutes... <mmccaws@comcast.net>
    Re: why is return always 0? <jameslockie@mail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 17 Mar 2008 19:17:12 -0000
From: "John" <john1949@yahoo.com>
Subject: cannot post message to perl beginners
Message-Id: <frmg3e$1pk$1@news.albasani.net>

This is odd.  I can post to this newsgroup but not to perl.beginners.

Anyone any idea why this is so?

Regards
John




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

Date: Mon, 17 Mar 2008 13:00:03 -0700 (PDT)
From: jammer <jameslockie@mail.com>
Subject: decrease MAC
Message-Id: <8af367a3-841d-4e2d-8045-71a8a0be6a87@d4g2000prg.googlegroups.com>

I have a hex number which is actually a MAC address and I want to find
the MAC immediately before.
0000AAAA9999

Is there a way to treat it as a hex number and do -1 one on it?


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

Date: Mon, 17 Mar 2008 09:46:28 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: FAQ 5.39 Why do I get weird spaces when I print an array of lines?
Message-Id: <86myox9znf.fsf@lifelogs.com>

On Sun, 16 Mar 2008 22:49:32 GMT Uri Guttman <uri@stemsystems.com> wrote: 

>>>>>> "BB" == Ben Bullock <benkasminbullock@gmail.com> writes:
BB> On Sun, 16 Mar 2008 06:03:03 -0700, PerlFAQ Server wrote:
>>> 5.39: Why do I get weird spaces when I print an array of lines?
>>> 
>>> Saying
>>> 
>>> print "@lines\n";
>>> 
>>> joins together the elements of @lines with a space between them.

BB> I recently learnt from a post here by Ben Morrow that it joins together 
BB> the elements of @lines with a $" between them:

BB> ben ~ 502 $ perl -e '$"="bu";@ba=("bo","be");print "@ba\n";'
BB> bobube

BB> Shouldn't this FAQ entry mention $"?

UG> technically you are correct but $" is rarely changed by newbies. its
UG> default value is space so the FAQ addresses that issue. it could be
UG> expanded to mention $" and perlvar but that may be too much info for a
UG> simple FAQ answer.

The problem is that the simple FAQ answer is wrong exactly when people
may be looking for reasons why there are weird separators in a list.

Note also that it doesn't just 'join' the elements but it also prints
them, which is obvious but still incorrect in the FAQ.

I think the FAQ should say:

Saying

print "@lines\n";

prints together the elements of @lines with a space between them (unless
$" has been changed from the default, see `perldoc perlvar').

Ted


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

Date: Mon, 17 Mar 2008 17:53:23 +0100
From: mirod <mirod@xmltwig.com>
Subject: Re: HTML parsing
Message-Id: <47dea201$0$21193$5fc30a8@news.tiscali.it>

June Lee wrote:
> any good way to extract the data?
> 
>  I want to parse the following HTML page and extract TV listing data
> using VC++
> 
> http://tvlistings.zap2it.com/tvlistings/ZCGrid.do
> 
> is easy for VC++ to call PERL script and do some regular expression?
> 
> since the HTML page is not XML well formed, I cannot use a XML parser
> right?
> 
> any other good ways to extract HTML page data?

You can use HTML::TreeBuilder, maybe the XML::LibXML html mode or
pre-process the HTML using tidy to generate XHTML.

In my experience, HTML::TreeBuilder is the easiest option.

If you need to navigate through the website to get to the page you need,
then WWW::Mechanize might help.

-- 
mirod


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

Date: 17 Mar 2008 15:44:07 GMT
From: xhoster@gmail.com
Subject: Re: Inside-out objects are slow! (or how to accelerate OO Perl?)
Message-Id: <20080317114408.437$Ap@newsreader.com>

Koszalek Opalek <koszalekopalek@interia.pl> wrote:
> I was about to redesign my class to use inside-out objects.
> I was hoping that except for a cleaner design it will also result in
> some performance boost.
> (I thought that 10 hashes with approx. 1000 keys will be faster than
> 1000 hashes with 10 keys.)

10 hashes with 100_000 keys might be more memory efficient than
100_000 hashes with 10 keys each, but I see no reason to think they
would be faster.

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: 17 Mar 2008 16:41:36 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Inside-out objects are slow! (or how to accelerate OO Perl?)
Message-Id: <slrnftt7q0.onm.abigail@alexandra.abigail.be>

                                                     _
Koszalek Opalek (koszalekopalek@interia.pl) wrote on VCCCXII September
MCMXCIII in <URL:news:9090114f-7541-4e6d-ba01-5ba62fe2dd40@13g2000hsb.googlegroups.com>:
@@  I was about to redesign my class to use inside-out objects.
@@  I was hoping that except for a cleaner design it will also result in
@@  some performance boost.

Inside Out Objects are *not* a cleaner design.

Inside Out Objects are all about getting the benefits of "strict" and 
"name spaces" into the world of objects. Nothing more, nothing less.
The programmer still has to do a lot of work which any decent language
ought to do for you, scribbling the state of an object away in hashes.

There's no performance boost, and Inside Out Objects don't claim to have any.

@@  (I thought that 10 hashes with approx. 1000 keys will be faster than
@@  1000 hashes with 10 keys.)

Yes, that's what one would expect. Apparently, that isn't always true.
In fact, Inside Out Objects don't even always use less memory.

@@  However, a simple experiment reveals that the opposite is true.
@@  Inside-out objects are approximately 3 times slower in this example --
@@  and it gets worse as the number of object grows.
@@  
@@  
@@  bash-3.2$ time ./makeregularobj.pl
@@  real    0m0.156s
@@  user    0m0.093s
@@  sys     0m0.000s
@@  
@@  bash-3.2$ time ./makeinsideoutobj.pl
@@  real    0m0.437s
@@  user    0m0.358s
@@  sys     0m0.015s
@@  
@@  I attach the two files below. Any comments?
@@  
@@  Apart from inside-out objects what other techniques could be used to
@@  accelerate OO Perl?

Write it in a different language? Not use OO? I mean, we're talking here about
a difference of 0.0000281 seconds per object creation. If such things
matter to you, are you sure Perl was the right choice? Once you have made
the decision to use Perl and OO, you have already sacrificed a lot of 
performance for convenience and design. 

Note also that your experiment only measures object construction. It
doesn't actually *do* anything with the objects. In a typical program,
you're more likely to spend more time inside methods than inside
constructors.

BTW, I've run a similar experiment, using traditional objects, 5.8 style
IOO objects, IOO objects using field hashes, and not using OO at all.
Measuring a combination of object (or data in the non-OO case) construction,
destruction, and calling a trivial method (just fetching data), 5.8 IOO
is about 2.5 times slower than traditional OO; field hashes is about 50%
time slower than 5.8 style IOO, but the clear winner was to not use objects
at all. Using traditional OO was about 3.5 times slower.

So, if speed is that important to you: DO NOT USE OBJECTS. (In fact, DO NOT
USE PERL AT ALL).



Abigail
-- 
sub J::FETCH{Just   }$_.='print+"@{[map';sub J::TIESCALAR{bless\my$J,J}
sub A::FETCH{Another}$_.='{tie my($x),$';sub A::TIESCALAR{bless\my$A,A}
sub P::FETCH{Perl   }$_.='_;$x}qw/J A P';sub P::TIESCALAR{bless\my$P,P}
sub H::FETCH{Hacker }$_.=' H/]}\n"';eval;sub H::TIESCALAR{bless\my$H,H}


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

Date: Mon, 17 Mar 2008 10:14:29 -0700 (PDT)
From: Koszalek Opalek <koszalekopalek@interia.pl>
Subject: Re: Inside-out objects are slow! (or how to accelerate OO Perl?)
Message-Id: <c795dd45-9102-496f-b619-93a9f8770e08@m36g2000hse.googlegroups.com>

On Mar 17, 4:44 pm, xhos...@gmail.com wrote:

> 10 hashes with 100_000 keys might be more memory efficient than
> 100_000 hashes with 10 keys each,

Yes, that's what I read here:
http://www.perlfoundation.org/perl5/index.cgi?inside_out_object

> but I see no reason to think they
> would be faster.

That was just a shot in the dark, I was hoping for some
less-memory -> fewer-cache-misses -> better-overall-speed
effect.


Koszalek


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

Date: Mon, 17 Mar 2008 10:33:19 -0700 (PDT)
From: Koszalek Opalek <koszalekopalek@interia.pl>
Subject: Re: Inside-out objects are slow! (or how to accelerate OO Perl?)
Message-Id: <753215ed-e212-4d7b-b270-e9d65deac0c4@b1g2000hsg.googlegroups.com>

On Mar 17, 9:41 am, david <michaelg...@gmail.com> wrote:

> I think that the point of inside-out objects is not to make OO safer
> and not faster, The real question is why do you need to make perl oo
> faster. In most cases it is fast enough.

So far, it has always been so for me... :-)

> There are pathological cases
> where you have to construct billions of objects. In this case you may
> choose a non oo solution (This is also true for compiled languages).

The thing is what is pathological for Perl?
Looks like this is thousands, not billions.

My module takes approx 1 sec to execute (on
the largest input). It has to create a few
thousand objects in the process. There is

1) Tree (only one)
2) Nodes (approximately 2ooo in the tree, and
   then ~2ooo outside the Tree)
3) Streams (basically arrays holding references to Nodes
   with some convenience methods, also a few thousands).

1 second is OK, 2 seconds would also be OK
but only just; so I am afraid that gives
me a very little safety margin for the future.

The thing is I never expected performance to be
a problem in the first place!

> The most important lesson I learned as programmer is "don;t optimize,
> profile". It can be that the bottle neck is in a place you never
> thought.

Sure, I ran the code through the profiler, I fixed some
brain-damage in the algorithm. That cut the execution
time by half. I can earn more by doing a few ugly things
like replacing $node->getproto() with $node->{proto} but
it looks like I'll never be able to go down to say 0.2 sec.

K.


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

Date: 17 Mar 2008 18:08:26 GMT
From: xhoster@gmail.com
Subject: Re: Inside-out objects are slow! (or how to accelerate OO Perl?)
Message-Id: <20080317140827.984$eF@newsreader.com>

Koszalek Opalek <koszalekopalek@interia.pl> wrote:
> On Mar 17, 4:44 pm, xhos...@gmail.com wrote:
>
> > 10 hashes with 100_000 keys might be more memory efficient than
> > 100_000 hashes with 10 keys each,
>
> Yes, that's what I read here:
> http://www.perlfoundation.org/perl5/index.cgi?inside_out_object
>
> > but I see no reason to think they
> > would be faster.
>
> That was just a shot in the dark, I was hoping for some
> less-memory -> fewer-cache-misses -> better-overall-speed
> effect.

You might be seeing the opposite.  With regular objects, you access
one hash ten times, and then do that 100_000 times with a different hash
each time.  With your inside out, are your accessing ten different hashes
once, then repeating that 100_000 times.  It may be less memory, but it has
worse locality of reference.  (But Perl has so much indirection that I
rarely consider locality of reference to be possible with it.)

Although it looks to me like another big time sink is in hashing
the scalar reference.  The regular method uses compile time literal
strings, and the hashing is done just once.

I don't see a way to get away from the locality of reference thing while
using inside out objects.  For the hashing, you could get much (but not
complete) benefit by do:

        my $self=1;
        my $rself=\$self;
        my $rrself="$rself";

And then using $rrself instead of retaking the reference to $self each time
you set a hash.  (There is a optimization that lets $rrself keep its hashed
value cached for faster access.  This optimization is not
implemented/possible for $self, nor apparently for $rself.)

But this is just for fun.  For serious work, I'd probably drop OO
altogether before I spent time micro-optimizing it.

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: Mon, 17 Mar 2008 11:18:47 -0700 (PDT)
From: Koszalek Opalek <koszalekopalek@interia.pl>
Subject: Re: Inside-out objects are slow! (or how to accelerate OO Perl?)
Message-Id: <fa1f1cfa-746c-421d-8f49-8e83fa38e133@d62g2000hsf.googlegroups.com>

On Mar 17, 5:41 pm, Abigail <abig...@abigail.be> wrote:

(..)
                                                      _
> So, if speed is that important to you: DO NOT USE OBJECTS. (In fact, DO NOT
> USE PERL AT ALL).


Wow, I would never expected that in perl.misc (at least not
in capital letters;-)

Actually, I've been entertaining the idea of rewriting the module
in C/C++ for some time. Chances are it would make it blindingly
fast, but the ease and convenience of Perl (and the ability to
hack/extend it by anyone) is not something I want to give up
lightly.

Anyway, I did some C/C++ vs Perl comparisons and that's what I
got for
- empty for loop
- calling an object method (simple accessor)
- modeling a struct with a hash

I looks that what really sucks is the last case, i.e. modeling a C
struct
with a hash (0.5 s vs 175 sec). Sure, comparing an STL map to a Perl
hash
would be more apples-to-apples (but hey, I would not need a map in C+
+).



-=-=- loop.exe -=-=-

real 0m3.666s
user 0m3.588s
sys 0m0.000s

-=-=- loop.pl -=-=-

real 1m29.700s
user 1m28.967s
sys 0m0.078s

-=-=- objmeth.exe -=-=-

real 0m54.974s
user 0m54.412s
sys 0m0.031s

-=-=- objmeth.pl -=-=-

real 8m42.731s
user 8m38.921s
sys 0m0.405s

-=-=- struct.exe -=-=-

real 0m0.562s
user 0m0.452s
sys 0m0.015s

-=-=- struct.pl -=-=-

real 2m54.990s
user 2m53.129s
sys 0m0.093s




===== loop.c =====

int main()
{
 volatile unsigned i;

 for (i=0; i< (1 << 30); i++);
};



=========================
===== loop.pl =====

#!/usr/bin/perl
my $i;

for ($i=0; $i< (1 << 30); $i++) {};



=========================
===== objmeth.cpp =====

class C {
public:

C (int i)
{
 data = i;
};

int get ()
{
 return data;
};

int set (int i)
{
 data = i;
};

private:
 volatile int data;
};



int main()
{
 C c0( 0 );
 C c1( 1 );
 C c2( 2 );
 C ct( 0 );
 volatile int i;

 for (i=0; i<100000; i++) {
  ct.set( c0.get() );
  c0.set( c1.get() );
  c1.set( c2.get() );
  c2.set( ct.get() );
 ....



=========================
===== objmeth.pl =====

#!/usr/bin/perl
use strict;

{
package P;

sub new {
 my $self = {data => $_[1]};
 bless $self, $_[0];
};

sub get {
 return $_[0]->{data};
}

sub set {
 $_[0]->{data} = $_[1];
};
};

my $o0 = P->new(0);
my $o1 = P->new(1);
my $o2 = P->new(2);
my $ot = P->new(0);
my $i;

for ($i=0; $i<100_000; $i++) {

 $ot->set( $o0->get() );
 $o0->set( $o1->get() );
 $o1->set( $o2->get() );
 $o2->set( $ot->get() );
 ....


=========================
===== struct.c =====

int main()
{
 typedef struct {
  unsigned a;
  unsigned b;
  unsigned c;
  unsigned d;
  unsigned f;
 } s_t;
 volatile s_t s;

 unsigned i;


 s.a = 1;
 s.b = 2;
 s.c = 3;
 s.d = 4;
 s.f;


 for (i = 0; i<10000; i++) {
  s.f = s.a;
  s.a = s.b;
  s.b = s.c;
  s.c = s.d;
  s.a = s.f;
 ...


=========================
===== struct.pl =====

#!/usr/bin/perl
use strict;

my %h = ( a=> 0, b => 0, c => 0, d => 0, f => 0 );
my $i;

$h{a} = 1;
$h{b} = 2;
$h{c} = 3;
$h{d} = 4;

for ($i=0; $i<10000; $i++)
{
 $h{f} = $h{a};
 $h{a} = $h{b};
 $h{b} = $h{c};
 $h{c} = $h{d};
 $h{a} = $h{f};
 ...


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

Date: Mon, 17 Mar 2008 11:30:57 -0700 (PDT)
From: Koszalek Opalek <koszalekopalek@interia.pl>
Subject: Re: Inside-out objects are slow! (or how to accelerate OO Perl?)
Message-Id: <0d97c88f-fd2b-4e46-a2cf-e4adbd4e3f88@m3g2000hsc.googlegroups.com>

On Mar 17, 7:08 pm, xhos...@gmail.com wrote:

> Although it looks to me like another big time sink is in hashing
> the scalar reference.  The regular method uses compile time literal
> strings, and the hashing is done just once.

How nice I found out before actually reworking the class :-)

Koszalek


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

Date: 17 Mar 2008 19:20:23 GMT
From: xhoster@gmail.com
Subject: Re: Inside-out objects are slow! (or how to accelerate OO Perl?)
Message-Id: <20080317152025.103$KP@newsreader.com>

Koszalek Opalek <koszalekopalek@interia.pl> wrote:
> On Mar 17, 5:41 pm, Abigail <abig...@abigail.be> wrote:
>
> (..)
>                                                       _
> > So, if speed is that important to you: DO NOT USE OBJECTS. (In fact, DO
> > NOT USE PERL AT ALL).
>
> Wow, I would never expected that in perl.misc (at least not
> in capital letters;-)

I think you must be new here.  People here very frequently point out when
they feel Perl just isn't the right tool for the job.  (Although we
sometimes disagree and argue about when exactly that is.)  Maybe groups
dedicated to other languages are more religious.

> Actually, I've been entertaining the idea of rewriting the module
> in C/C++ for some time. Chances are it would make it blindingly
> fast, but the ease and convenience of Perl (and the ability to
> hack/extend it by anyone) is not something I want to give up
> lightly.

I wouldn't consider Perl as a good language for the criteria that anyone be
able to hack/extend code written in it.  I would think Java would be more
along those lines.

>
> Anyway, I did some C/C++ vs Perl comparisons and that's what I
> got for
> - empty for loop
> - calling an object method (simple accessor)
> - modeling a struct with a hash
>
> I looks that what really sucks is the last case, i.e. modeling a C
> struct
> with a hash (0.5 s vs 175 sec).

I think you might be missing the point.  Yes, a struct-element assignment
in C is about as fast a atomic variable assignment is in C, while in Perl
a hash-element assignment is substantially slower (~2.5x, it looks like)
than a pure-scalar assignment.  But the real issue is that any assignment
in Perl, even if not a hash element, is ~100 slower than any assignment in
C.

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: Mon, 17 Mar 2008 20:20:41 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: Inside-out objects are slow! (or how to accelerate OO Perl?)
Message-Id: <873aqpf986.fsf@zeekat.nl>

Koszalek Opalek <koszalekopalek@interia.pl> writes:

> On Mar 17, 5:41 pm, Abigail <abig...@abigail.be> wrote:
>
> (..)
>                                                       _
>> So, if speed is that important to you: DO NOT USE OBJECTS. (In fact, DO NOT
>> USE PERL AT ALL).
>
>
> Wow, I would never expected that in perl.misc (at least not
> in capital letters;-)

Well, it's true. :-) Method calls and object instantiation are
especially slow compared to C++. If you're working with more than a few
hundred thousand objects, and you can capture the functionality in a
small XS interface (for instance, don't iterate over objects in perl
space) you can expect a very dramatic increase in speed (and also
probably a pretty good reduction in memory use). Usually you don't need
it, but when you do...

> Actually, I've been entertaining the idea of rewriting the module
> in C/C++ for some time. Chances are it would make it blindingly
> fast, but the ease and convenience of Perl (and the ability to
> hack/extend it by anyone) is not something I want to give up
> lightly.

You should only put those parts that really matter in C/C++ space. All
the annoying stuff (loading databases, parsing files, user interface
etc) is much better handled in perl. XS takes some getting used to but
once you're familiar with it it's really pretty easy to move parts of
your perl code to XS (except for those damn reference counts).

> Anyway, I did some C/C++ vs Perl comparisons and that's what I
> got for
> - empty for loop
> - calling an object method (simple accessor)
> - modeling a struct with a hash

Those kinds of tests are *usually* not very relevant unless your objects
are so simple that you'd be much better off not using objects at all
(even if you go for C++).

> I looks that what really sucks is the last case, i.e. modeling a C
> struct
> with a hash (0.5 s vs 175 sec).

C structs are actually more like arrays. You could try modelling with an
array instead;

# this should inline the field names
use constant {
  FIELDA => 0,
  FIELDB => 1,
};  

my @o = ['val1','val2'];

print $o[FIELDA];
print $o[FIELDB];

I don't expect that to be *much* faster, but at least it gives you
some typo-checking.

> (but hey, I would not need a map in C+ +).

Don't be too sure. :-)

-- 
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/


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

Date: Mon, 17 Mar 2008 19:15:03 -0000
From: "John" <john1949@yahoo.com>
Subject: test
Message-Id: <frmfvd$1jl$1@news.albasani.net>

please ignore 




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

Date: Mon, 17 Mar 2008 08:10:43 -0700 (PDT)
From: mmccaws2 <mmccaws@comcast.net>
Subject: trying to execute 'at now + 2 minutes...
Message-Id: <7b96d3e0-5244-4928-b3a3-08e79651cd27@i12g2000prf.googlegroups.com>

Hi

On unix I'll run a command at the command line  like

> at now + 2 minutes
> ./trial.pl &
> Ctrl d

how do I do this from within a script?

Thanks
Mike


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

Date: Mon, 17 Mar 2008 08:37:35 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: trying to execute 'at now + 2 minutes...
Message-Id: <86r6e9wedc.fsf@blue.stonehenge.com>

>>>>> "mmccaws2" == mmccaws2  <mmccaws@comcast.net> writes:

mmccaws2> Hi
mmccaws2> On unix I'll run a command at the command line  like

>> at now + 2 minutes
>> ./trial.pl &
>> Ctrl d

mmccaws2> how do I do this from within a script?

open AT, "|at now + 2 minutes" or die $!;
print AT "./trial.pl"; # not sure why you backgrounded that.
close AT;

Or, if you don't really need "at", and you just want to execute something
in two minutes, you can simply fork:

defined(my $kid = fork) or die "Cannot fork: $!";
unless ($kid) { # child does...
   sleep 2 * 60; # two minutes, measured in seconds
   exec "./trial.pl"; # for example, or just do it in line
   exit 0;
}

$kid's pid will show up on a waitpid() call later, so you need to wait for it
eventually or exit soon, or you can double fork and wait if you don't want the
zombie.

print "Just another Perl hacker,"; # the original, #0 :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Mon, 17 Mar 2008 08:45:04 -0700 (PDT)
From: sandy_saydakov@yahoo.com
Subject: Re: trying to execute 'at now + 2 minutes...
Message-Id: <c8acddb2-1cba-4dfa-8efe-1d66ef823fda@s8g2000prg.googlegroups.com>

On 17 Mar, 08:10, mmccaws2 <mmcc...@comcast.net> wrote:
>
> On unix I'll run a command at the command line  like
>
> > at now + 2 minutes
> > ./trial.pl &
> > Ctrl d
>
> how do I do this from within a script?

Perhaps, sleep($seconds) first would do it for you.

/sandy
http://myperlquiz.com/


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

Date: 17 Mar 2008 15:51:13 GMT
From: xhoster@gmail.com
Subject: Re: trying to execute 'at now + 2 minutes...
Message-Id: <20080317115115.322$tp@newsreader.com>

mmccaws2 <mmccaws@comcast.net> wrote:
> Hi
>
> On unix I'll run a command at the command line  like
>
> > at now + 2 minutes
> > ./trial.pl &
> > Ctrl d
>
> how do I do this from within a script?

open my $at, "| at now + 2 minutes" or die $!;
print $at './trial.pl&';
close $at or die $!;

Or you could do it strictly in Perl using fork and sleep and exec.

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: Mon, 17 Mar 2008 09:10:32 -0700 (PDT)
From: mmccaws2 <mmccaws@comcast.net>
Subject: Re: trying to execute 'at now + 2 minutes...
Message-Id: <6b982c97-6b5a-4c36-86bf-ba642986f651@d4g2000prg.googlegroups.com>

On Mar 17, 8:51 am, xhos...@gmail.com wrote:
> mmccaws2 <mmcc...@comcast.net> wrote:
> > Hi
>
> > On unix I'll run a command at the command line  like
>
> > > at now + 2 minutes
> > > ./trial.pl &
> > > Ctrl d
>
> > how do I do this from within a script?
>
> open my $at, "| at now + 2 minutes" or die $!;
> print $at './trial.pl&';
> close $at or die $!;
>
> Or you could do it strictly in Perl using fork and sleep and exec.
>
> 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.

Thanks everyone

it works great.

Mike


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

Date: Mon, 17 Mar 2008 12:56:39 -0700 (PDT)
From: jammer <jameslockie@mail.com>
Subject: Re: why is return always 0?
Message-Id: <b59896fe-cfe7-4b5a-974c-54ad3d7b5e83@i29g2000prf.googlegroups.com>

On Mar 16, 9:10 pm, sandy_sayda...@yahoo.com wrote:
> On 16 Mar, 17:45, jammer <jamesloc...@mail.com> wrote:
>
> > How do I make tftp fail if the host is bad?
>
> >         my $rc = system( "/usr/bin/tftp bad$host < $tempFile 2>&1 >/dev/null" );
> >         if ( $rc != 0 ) {
> >                 print "unable to tftp to '$host'\n";
> >                 exit 1;
> >         } else {
> >                 print "success: $rc\n";
> >         }
>
> Make sure the binary returns non-zero on failure. Try that command on
> the command line and do "echo $?" right after.
>
> -sandyhttp://myperlquiz.com/

It prints an error when run interactively.
tftp does run, it just can't find the host.
It returns  0 because it ran, didn't work but it ran. :-(


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

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


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