[32254] in Perl-Users-Digest
Perl-Users Digest, Issue: 3521 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 16 16:09:20 2011
Date: Sun, 16 Oct 2011 13:09:05 -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, 16 Oct 2011 Volume: 11 Number: 3521
Today's topics:
File Rotation <1dg618@gmail.com>
Re: File Rotation <news@lawshouse.org>
Re: File Rotation <1dg618@gmail.com>
Re: File Rotation <jurgenex@hotmail.com>
Re: File Rotation <1dg618@gmail.com>
Re: File Rotation <1dg618@gmail.com>
Re: File Rotation <1dg618@gmail.com>
Re: help with pipe (Jens Thoms Toerring)
Re: help with pipe <hjp-usenet2@hjp.at>
Re: help with pipe <jurgenex@hotmail.com>
Re: help with pipe <bjlockie@lockie.ca>
Re: help with pipe <jurgenex@hotmail.com>
Re: help with pipe <bjlockie@lockie.ca>
Re: help with pipe <bjlockie@lockie.ca>
Re: Questions re using Require <rweikusat@mssgmbh.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 16 Oct 2011 07:43:58 -0700 (PDT)
From: 1dg618 <1dg618@gmail.com>
Subject: File Rotation
Message-Id: <7c4b4ca0-55cd-48ee-9c29-0e7b9169acf8@k2g2000yqh.googlegroups.com>
Is there a way to rotate the log files each time the process runs
using the existing functionality via the configuration? If the process
has issues, the most recent log file logged the information. I can't
find a way, but, I assume, others have found a way?
------------------------------
Date: Sun, 16 Oct 2011 17:10:11 +0100
From: Henry Law <news@lawshouse.org>
Subject: Re: File Rotation
Message-Id: <IeWdnXK5WcB1nAbTnZ2dnUVZ7sGdnZ2d@giganews.com>
On 16/10/11 15:43, 1dg618 wrote:
> Is there a way to rotate the log files each time the process runs
> using the existing functionality via the configuration? If the process
> has issues, the most recent log file logged the information. I can't
> find a way, but, I assume, others have found a way?
Newsgroups these days are infested with posts which contain
randomly-chosen words which mean nothing. I thought this was one of
them initially but maybe it isn't.
Mr/Ms 1dg618 (May I call you "One d" for short?) for us to help you're
going to need to be much more precise about what you're trying to do and
what's not happening the way you want it to.
For a start, Perl programs (this is a Perl group) don't write log files
unless you tell them to. Once they're written they're the property of
the operating system, which may provide log-rotation functionality (UNIX
does, for example).
And when you say "the existing functionality via the configuration",
which functionality and which configuration? (And of what?)
CPAN contains many modules which have "log file" in their descriptive
text. It's possible that one of those may do exactly what you want, but
until you make clear what it is that you want we can't help you further.
--
Henry Law Manchester, England
------------------------------
Date: Sun, 16 Oct 2011 09:26:59 -0700 (PDT)
From: 1dg618 <1dg618@gmail.com>
Subject: Re: File Rotation
Message-Id: <af9ee557-77e2-4e4e-849f-e64704e4f5e2@u2g2000yqi.googlegroups.com>
On Oct 16, 11:10=A0am, Henry Law <n...@lawshouse.org> wrote:
> On 16/10/11 15:43, 1dg618 wrote:
>
> > Is there a way to rotate the log files each time the process runs
> > using the existing functionality via the configuration? If the process
> > has issues, the most recent log file logged the information. I can't
> > find a way, but, I assume, others have found a way?
>
> Newsgroups these days are infested with posts which contain
> randomly-chosen words which mean nothing. =A0I thought this was one of
> them initially but maybe it isn't.
>
> Mr/Ms 1dg618 (May I call you "One d" for short?) for us to help you're
> going to need to be much more precise about what you're trying to do and
> what's not happening the way you want it to.
>
> For a start, Perl programs (this is a Perl group) don't write log files
> unless you tell them to. =A0Once they're written they're the property of
> the operating system, which may provide log-rotation functionality (UNIX
> does, for example).
>
> And when you say "the existing functionality via the configuration",
> which functionality and which configuration? =A0(And of what?)
>
> CPAN contains many modules which have "log file" in their descriptive
> text. =A0It's possible that one of those may do exactly what you want, bu=
t
> until you make clear what it is that you want we can't help you further.
>
> --
>
> Henry Law =A0 =A0 =A0 =A0 =A0 =A0Manchester, England
Sorry, using Log4Perl. I'll look for a Log4Perl user group.
------------------------------
Date: Sun, 16 Oct 2011 09:34:50 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: File Rotation
Message-Id: <hp1m97tmhn28kn16hvj70s2gm4r5bj3rsp@4ax.com>
1dg618 <1dg618@gmail.com> wrote:
>Is there a way to rotate the log files
What log files?
> each time the process runs
What process runs? fork()ed by Perl? Your program itself?
>using the existing functionality via the configuration?
What existing functionality of what and what configuration?
>If the process
>has issues, the most recent log file logged the information. I can't
>find a way, but, I assume, others have found a way?
Mysterious your words are....
jue
------------------------------
Date: Sun, 16 Oct 2011 09:27:43 -0700 (PDT)
From: 1dg618 <1dg618@gmail.com>
Subject: Re: File Rotation
Message-Id: <1ecd21b9-6bbf-4f2d-b002-f59a6369c449@c1g2000vbw.googlegroups.com>
On Oct 16, 11:10=A0am, Henry Law <n...@lawshouse.org> wrote:
> On 16/10/11 15:43, 1dg618 wrote:
>
> > Is there a way to rotate the log files each time the process runs
> > using the existing functionality via the configuration? If the process
> > has issues, the most recent log file logged the information. I can't
> > find a way, but, I assume, others have found a way?
>
> Newsgroups these days are infested with posts which contain
> randomly-chosen words which mean nothing. =A0I thought this was one of
> them initially but maybe it isn't.
>
> Mr/Ms 1dg618 (May I call you "One d" for short?) for us to help you're
> going to need to be much more precise about what you're trying to do and
> what's not happening the way you want it to.
>
> For a start, Perl programs (this is a Perl group) don't write log files
> unless you tell them to. =A0Once they're written they're the property of
> the operating system, which may provide log-rotation functionality (UNIX
> does, for example).
>
> And when you say "the existing functionality via the configuration",
> which functionality and which configuration? =A0(And of what?)
>
> CPAN contains many modules which have "log file" in their descriptive
> text. =A0It's possible that one of those may do exactly what you want, bu=
t
> until you make clear what it is that you want we can't help you further.
>
> --
>
> Henry Law =A0 =A0 =A0 =A0 =A0 =A0Manchester, England
I'm using Log4Perl. If I wrote my own with Perl, I wouldn't have to
ask the question. Right?
------------------------------
Date: Sun, 16 Oct 2011 10:17:42 -0700 (PDT)
From: 1dg618 <1dg618@gmail.com>
Subject: Re: File Rotation
Message-Id: <60b9a9e0-0a71-4517-967d-bdaee7f3c543@o19g2000vbk.googlegroups.com>
On Oct 16, 11:34=A0am, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> 1dg618 <1dg...@gmail.com> wrote:
> >Is there a way to rotate the log files
>
> What log files?
>
> > each time the process runs
>
> What process runs? fork()ed by Perl? Your program itself?
>
> >using the existing functionality via the configuration?
>
> What existing functionality of what and what configuration?
>
> >If the process
> >has issues, the most recent log file logged the information. I can't
> >find a way, but, I assume, others have found a way?
>
> Mysterious your words are....
>
> jue
Sorry, I was talking about Log4Perl. Here's my configuration:
my $log_conf =3D q/
log4perl.category =3D INFO, Logfile
log4perl.appender.Logfile=3DLog::Dispatch::FileRotate
log4perl.appender.Logfile.max=3D10
log4perl.appender.Logfile.mode=3Dappend
log4perl.appender.Logfile.filename=3Dsub { return get_log_fn(); }
log4perl.appender.Logfile.DatePattern=3Dyyyy-MM-dd
log4perl.appender.Logfile.TZ=3DCST
=20
log4perl.appender.Logfile.layout=3DLog::Log4perl::Layout::PatternLayout
log4perl.appender.Logfile.layout.ConversionPattern=3D%d %M %L> %p -
%m%n
/;
Using the DatePattern, I can rotate the logs every hour, but I'd like
to rotate the log files each time the process I created runs. I don't
know if there is a way using Log4Perl?
------------------------------
Date: Sun, 16 Oct 2011 09:31:37 -0700 (PDT)
From: 1dg618 <1dg618@gmail.com>
Subject: Re: File Rotation
Message-Id: <08b1a2e2-4487-47ff-9238-3062c8a30f32@v28g2000vby.googlegroups.com>
On Oct 16, 11:26=A0am, 1dg618 <1dg...@gmail.com> wrote:
> On Oct 16, 11:10=A0am, Henry Law <n...@lawshouse.org> wrote:
>
>
>
>
>
> > On 16/10/11 15:43, 1dg618 wrote:
>
> > > Is there a way to rotate the log files each time the process runs
> > > using the existing functionality via the configuration? If the proces=
s
> > > has issues, the most recent log file logged the information. I can't
> > > find a way, but, I assume, others have found a way?
>
> > Newsgroups these days are infested with posts which contain
> > randomly-chosen words which mean nothing. =A0I thought this was one of
> > them initially but maybe it isn't.
>
> > Mr/Ms 1dg618 (May I call you "One d" for short?) for us to help you're
> > going to need to be much more precise about what you're trying to do an=
d
> > what's not happening the way you want it to.
>
> > For a start, Perl programs (this is a Perl group) don't write log files
> > unless you tell them to. =A0Once they're written they're the property o=
f
> > the operating system, which may provide log-rotation functionality (UNI=
X
> > does, for example).
>
> > And when you say "the existing functionality via the configuration",
> > which functionality and which configuration? =A0(And of what?)
>
> > CPAN contains many modules which have "log file" in their descriptive
> > text. =A0It's possible that one of those may do exactly what you want, =
but
> > until you make clear what it is that you want we can't help you further=
.
>
> > --
>
> > Henry Law =A0 =A0 =A0 =A0 =A0 =A0Manchester, England
>
> Sorry, using Log4Perl. I'll look for a Log4Perl user group.- Hide quoted =
text -
>
> - Show quoted text -
My Log4Perl configuration rotates the log files daily. Using the
DatePattern I can get that down to minutes. How do you get the log
files to rotate everytime the process runs? Is there a way to do it in
Log4Perl?
my $log_conf =3D q/
log4perl.category =3D INFO, Logfile
log4perl.appender.Logfile=3DLog::Dispatch::FileRotate
log4perl.appender.Logfile.max=3D10
log4perl.appender.Logfile.mode=3Dappend
log4perl.appender.Logfile.filename=3Dsub { return get_log_fn(); }
log4perl.appender.Logfile.DatePattern=3Dyyyy-MM-dd
log4perl.appender.Logfile.TZ=3DCST
=20
log4perl.appender.Logfile.layout=3DLog::Log4perl::Layout::PatternLayout
log4perl.appender.Logfile.layout.ConversionPattern=3D%d %M %L> %p -
%m%n
/;
Otherwise, I'll have to use Herny's suggestion and write my own code
to do it.
------------------------------
Date: 16 Oct 2011 10:39:46 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: help with pipe
Message-Id: <9fvqjiFnkuU1@mid.uni-berlin.de>
bjlockie <bjlockie@lockie.ca> wrote:
> This code never gets to 'here3'.
> I think because the command ping never finishes (ping is an example
> command, there are no switches to make the real command stop).
> I've seen similar code working elsewhere.
> my $cmd = 'ping google.ca >/dev/null |';
> open( ZAP, $cmd ) || die "can't fork: $!";
You'd nowadays better use the three-argument form of open
and variables for file handles:
my $cmd = 'ping google.ca > /dev/null';
open my $zap, '-|', $cmd or die "can't fork: $!";
> print $cmd . "\n";
> print "here2\n";
> while (my $line = <ZAP>) {
> print $line;
> }
> print "here3\n";
Yes, of course, if ping never finishes, why should the loop
terminate? If you want it to end you must decide on a condi-
tion and implement that. One possibility would be to stop
after a certain number of lines - add a counter that you
increment in the loop and use in the loop condition. Another
condition could be that you only want to read for a certain
time, this could be dealt with with by setting up a timer (e.g.
with the alarm() function) that raises the SIGALRMsignal and
kill the process in the handler for that signal (the PID of
the spawned process is what open returns). Something like
use strict;
use warnings;
my $cmd = 'ping google.ca > /dev/null';
my $pid = open my $zap, '-|', $cmd or die "can't fork: $!";
$SIG{ ALRM } = sub { kill 'TERM', $pid };
print "here2\n";
alarm 3;
while ( my $line = <$zap> ) {
print $line;
}
print "here3\n";
should do the job of getting out of the loop after 3 seconds.
Sorry, without knowing what you want to achieve it's a bit
difficult to be more specific.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
------------------------------
Date: Sun, 16 Oct 2011 13:21:47 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: help with pipe
Message-Id: <slrnj9lfib.uga.hjp-usenet2@hrunkner.hjp.at>
On 2011-10-16 07:57, bjlockie <bjlockie@lockie.ca> wrote:
> Create ./channels.conf with the single line:
> CBC:539000000:8VSB:49:52:3
>
>
> This code never gets to 'here3'.
Jens already explained that.
> I think because the command ping never finishes (ping is an example
> command, there are no switches to make the real command stop).
> I've seen similar code working elsewhere.
>
>
> my $cmd = 'ping google.ca >/dev/null |';
>
> open( ZAP, $cmd ) || die "can't fork: $!";
What do you expect to read from the pipe? You have redirected the
standard output (which would normally go to the pipe) to /dev/null.
hp
------------------------------
Date: Sun, 16 Oct 2011 04:36:06 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: help with pipe
Message-Id: <srfl97h5skeiscm7nh9s0g9rgun56kqs91@4ax.com>
bjlockie <bjlockie@lockie.ca> wrote:
>This code never gets to 'here3'.
>I think because the command ping never finishes (ping is an example
>command, there are no switches to make the real command stop).
>I've seen similar code working elsewhere.
>
>
> my $cmd = 'ping google.ca >/dev/null |';
>
> open( ZAP, $cmd ) || die "can't fork: $!";
This has nothing to do with fork. A more accurate message would be
"can't run $cmd because $!"
>print $cmd . "\n";
>
>print "here2\n";
>
> while (my $line = <ZAP>) {
> print $line;
> }
>
>print "here3\n";
Well, of course it doesn't. $cmd never terminates, therefore ZAP is
never closed, and therefore the while loop can't terminate either,
because there is always the chance, that after 1000 eternities there
might be output from $cmd.
I am not sure what your goal is here.
If you just want to run the other command while ignoring its output,
then just start it in the background or fork() a new process.
If you want to capture part of the output then you will have to decide
what part of that output is relevant to you: the first x lines, the
first y hours, the first z characters, all output until a certain
pattern, .... and use that as the termination condition for the loop.
jue
------------------------------
Date: Sun, 16 Oct 2011 09:35:25 -0700 (PDT)
From: bjlockie <bjlockie@lockie.ca>
Subject: Re: help with pipe
Message-Id: <7e499597-5d04-42f9-95e3-432b8101925b@v11g2000vbm.googlegroups.com>
On Oct 16, 7:36=A0am, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> bjlockie <bjloc...@lockie.ca> wrote:
> >This code never gets to 'here3'.
> >I think because the command ping never finishes (ping is an example
> >command, there are no switches to make the real command stop).
> >I've seen similar code working elsewhere.
>
> > =A0 =A0my $cmd =3D 'ping google.ca >/dev/null |';
>
> > =A0 =A0open( ZAP, $cmd ) || die "can't fork: $!";
>
> This has nothing to do with fork. A more accurate message would be
> "can't run $cmd because $!"
>
> >print $cmd . "\n";
>
> >print "here2\n";
>
> > =A0 =A0while (my $line =3D <ZAP>) {
> > =A0 =A0 =A0 =A0print $line;
> > =A0 =A0}
>
> >print "here3\n";
>
> Well, of course it doesn't. $cmd never terminates, therefore ZAP is
> never closed, and therefore the while loop can't terminate either,
> because there is always the chance, that after 1000 eternities there
> might be output from $cmd.
>
> I am not sure what your goal is here.
> If you just want to run the other command while ignoring its output,
> then just start it in the background or fork() a new process.
> If you want to capture part of the output then you will have to decide
> what part of that output is relevant to you: the first x lines, the
> first y hours, the first z characters, all output until a certain
> pattern, .... and use that as the termination condition for the loop.
>
> jue
my $cmd =3D 'ping google.ca
|';
open( ZAP, $cmd ) || die "can't fork:
$!";
print $cmd .
"\n";
print
"here2\n";
my $numLines =3D
0;
while (($numLines < 10) && (my $line =3D <ZAP>))
{
print
$line;
$numLines+
+;
}
print "here3\n";
That doesn't exit the while loop and it prints the ping output to the
screen.
------------------------------
Date: Sun, 16 Oct 2011 09:47:22 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: help with pipe
Message-Id: <nf2m979jfucbftn40ohg5dal1c1hhdu8ot@4ax.com>
bjlockie <bjlockie@lockie.ca> wrote:
>On Oct 16, 7:36 am, Jürgen Exner <jurge...@hotmail.com> wrote:
>> bjlockie <bjloc...@lockie.ca> wrote:
>> >This code never gets to 'here3'.
>> >I think because the command ping never finishes (ping is an example
>> >command, there are no switches to make the real command stop).
>> >I've seen similar code working elsewhere.
>>
>> > my $cmd = 'ping google.ca >/dev/null |';
>>
>> > open( ZAP, $cmd ) || die "can't fork: $!";
>>
>> This has nothing to do with fork. A more accurate message would be
>> "can't run $cmd because $!"
>>
>> >print $cmd . "\n";
>>
>> >print "here2\n";
>>
>> > while (my $line = <ZAP>) {
>> > print $line;
>> > }
>>
>> >print "here3\n";
>>
>> Well, of course it doesn't. $cmd never terminates, therefore ZAP is
>> never closed, and therefore the while loop can't terminate either,
>> because there is always the chance, that after 1000 eternities there
>> might be output from $cmd.
>>
>> I am not sure what your goal is here.
>> If you just want to run the other command while ignoring its output,
>> then just start it in the background or fork() a new process.
>> If you want to capture part of the output then you will have to decide
>> what part of that output is relevant to you: the first x lines, the
>> first y hours, the first z characters, all output until a certain
>> pattern, .... and use that as the termination condition for the loop.
[replacing program with better readable formatting]
use warnings;
use strict;
my $cmd = 'ping google.ca|';
open( ZAP, $cmd ) || die "can't fork:$!";
print $cmd ."\n";
print "here2\n";
my $numLines = 0;
while (($numLines < 10) && (my $line = <ZAP>)){
print $line;
$numLines++;
}
print "here3\n";
>That doesn't exit the while loop and it prints the ping output to the
>screen.
Can't repro your problem. It does stop for me. And if I replace the 10
with a lower number, e.g. 4, it will stop even in the middle of the ping
reports.
jue
------------------------------
Date: Sun, 16 Oct 2011 09:49:49 -0700 (PDT)
From: bjlockie <bjlockie@lockie.ca>
Subject: Re: help with pipe
Message-Id: <79b9faba-175e-422a-b037-07c0e13c53f4@f13g2000vbv.googlegroups.com>
On Oct 16, 12:47=A0pm, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> bjlockie <bjloc...@lockie.ca> wrote:
> >On Oct 16, 7:36=A0am, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> >> bjlockie <bjloc...@lockie.ca> wrote:
> >> >This code never gets to 'here3'.
> >> >I think because the command ping never finishes (ping is an example
> >> >command, there are no switches to make the real command stop).
> >> >I've seen similar code working elsewhere.
>
> >> > =A0 =A0my $cmd =3D 'ping google.ca >/dev/null |';
>
> >> > =A0 =A0open( ZAP, $cmd ) || die "can't fork: $!";
>
> >> This has nothing to do with fork. A more accurate message would be
> >> "can't run $cmd because $!"
>
> >> >print $cmd . "\n";
>
> >> >print "here2\n";
>
> >> > =A0 =A0while (my $line =3D <ZAP>) {
> >> > =A0 =A0 =A0 =A0print $line;
> >> > =A0 =A0}
>
> >> >print "here3\n";
>
> >> Well, of course it doesn't. $cmd never terminates, therefore ZAP is
> >> never closed, and therefore the while loop can't terminate either,
> >> because there is always the chance, that after 1000 eternities there
> >> might be output from $cmd.
>
> >> I am not sure what your goal is here.
> >> If you just want to run the other command while ignoring its output,
> >> then just start it in the background or fork() a new process.
> >> If you want to capture part of the output then you will have to decide
> >> what part of that output is relevant to you: the first x lines, the
> >> first y hours, the first z characters, all output until a certain
> >> pattern, .... and use that as the termination condition for the loop.
>
> [replacing program with better readable formatting]
>
> use warnings;
> use strict;
> my $cmd =3D 'ping google.ca|';
>
> open( ZAP, $cmd ) || die "can't fork:$!";
>
> print $cmd ."\n";
> print "here2\n";
> my $numLines =3D 0;
>
> while (($numLines < 10) && (my $line =3D <ZAP>)){
> =A0 =A0 print $line;
> =A0 =A0 $numLines++;}
>
> print "here3\n";
>
> >That doesn't exit the while loop and it prints the ping output to the
> >screen.
>
> Can't repro your problem. It does stop for me. And if I replace the 10
> with a lower number, e.g. 4, it will stop even in the middle of the ping
> reports.
>
> jue
Thanks for the help.
------------------------------
Date: Sun, 16 Oct 2011 09:49:21 -0700 (PDT)
From: bjlockie <bjlockie@lockie.ca>
Subject: Re: help with pipe
Message-Id: <26b559f1-f2a5-46b7-9a07-c928a01836ab@v11g2000vbm.googlegroups.com>
On Oct 16, 12:47=A0pm, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> bjlockie <bjloc...@lockie.ca> wrote:
> >On Oct 16, 7:36=A0am, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> >> bjlockie <bjloc...@lockie.ca> wrote:
> >> >This code never gets to 'here3'.
> >> >I think because the command ping never finishes (ping is an example
> >> >command, there are no switches to make the real command stop).
> >> >I've seen similar code working elsewhere.
>
> >> > =A0 =A0my $cmd =3D 'ping google.ca >/dev/null |';
>
> >> > =A0 =A0open( ZAP, $cmd ) || die "can't fork: $!";
>
> >> This has nothing to do with fork. A more accurate message would be
> >> "can't run $cmd because $!"
>
> >> >print $cmd . "\n";
>
> >> >print "here2\n";
>
> >> > =A0 =A0while (my $line =3D <ZAP>) {
> >> > =A0 =A0 =A0 =A0print $line;
> >> > =A0 =A0}
>
> >> >print "here3\n";
>
> >> Well, of course it doesn't. $cmd never terminates, therefore ZAP is
> >> never closed, and therefore the while loop can't terminate either,
> >> because there is always the chance, that after 1000 eternities there
> >> might be output from $cmd.
>
> >> I am not sure what your goal is here.
> >> If you just want to run the other command while ignoring its output,
> >> then just start it in the background or fork() a new process.
> >> If you want to capture part of the output then you will have to decide
> >> what part of that output is relevant to you: the first x lines, the
> >> first y hours, the first z characters, all output until a certain
> >> pattern, .... and use that as the termination condition for the loop.
>
> [replacing program with better readable formatting]
>
> use warnings;
> use strict;
> my $cmd =3D 'ping google.ca|';
>
> open( ZAP, $cmd ) || die "can't fork:$!";
>
> print $cmd ."\n";
> print "here2\n";
> my $numLines =3D 0;
>
> while (($numLines < 10) && (my $line =3D <ZAP>)){
> =A0 =A0 print $line;
> =A0 =A0 $numLines++;}
>
> print "here3\n";
>
> >That doesn't exit the while loop and it prints the ping output to the
> >screen.
>
> Can't repro your problem. It does stop for me. And if I replace the 10
> with a lower number, e.g. 4, it will stop even in the middle of the ping
> reports.
>
> jue
I was just going to update my post saying it works now. :-)
------------------------------
Date: Sun, 16 Oct 2011 20:20:26 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Questions re using Require
Message-Id: <8739eslp51.fsf@sapphire.mobileactivedefense.com>
"Joey@still_Learning.invalid" <Joey@still_Learning.invalid> writes:
> My web application produces three slightly different versions of the same
> page, so I think I want to use 'Require' to import a lot of the common
> code for all three pages. A couple of questions:
>
> 1. Do I put the 'require' statement in the script at the place I want to
> import the code, or can it be placed at the start of the script?
It can be placed at the start of the script and IMO, it should also be
placed there: It's easier to determine what other files will be used
when some code is going to be executed when 'inclusion of other files'
always happens at the same, prominent location. Putting require into a
BEGIN block so that it is processed at the same time all the other
code passes through the compiler (or using use instead of require)
should also be considered.
> 2. Two of the three pages print the contents to the screen (e.g., print
> "content\n";), but the third page prints the contents to a file, e.g.,
> print tfile "content\n", although some of the third page also prints to
> the screen.
>
> Is it somehow possible to use Require for all three pages? How do I
> account for writing content to the file?
Two ways to do this which suggest themselves would be
- pass the output file handle as argument, using \*STDOUT for
printing 'to the screen' (if the code is suitably structured
for that)
- remove any explicitly specified filehandles from the code
and use select(FILEHANDLE) to set a suitable 'default output
filehandle'.
------------------------------
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 3521
***************************************