[7800] in Perl-Users-Digest
Perl-Users Digest, Issue: 1425 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 6 05:16:59 1997
Date: Sat, 6 Dec 97 02:01:55 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 6 Dec 1997 Volume: 8 Number: 1425
Today's topics:
Re: printing and screen output <barnett@houston.Geco-Prakla.slb.com>
Re: printing and screen output (Tad McClellan)
Problem with function call to ps() <jlee@mdsi.bc.ca>
Re: Question about the =~ operator <barnett@houston.Geco-Prakla.slb.com>
replacement for fork() on NT? (Jeff Kehoe)
Re: Returning Values from a Perl script <rootbeer@teleport.com>
Re: searching indexed file <rootbeer@teleport.com>
Re: Seems to be just another 5.004_* bug:-( <tycage@infi.net>
Re: Setting default printer under Windows NT <rootbeer@teleport.com>
Re: the skinny on my() vs local() - thanks to all <davidk@nospam.cnct.com>
Re: the skinny on my() vs local() - thanks <davidk@nospam.cnct.com>
Re: validation problem <rootbeer@teleport.com>
Re: Win32-Perl: How to get location of NT system direc <bowlin@sirius.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 05 Dec 1997 12:50:36 -0600
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
To: "David R. Adams" <dradams@bigfoot.com>
Subject: Re: printing and screen output
Message-Id: <34884CFA.3F478039@houston.Geco-Prakla.slb.com>
David Adams wrote:
> Hi,
>
> I didn't find the answer to this question in the FAQ.
>
> How do you force print output without a linefeed ("\n")? I would like to
> have a program continue to print to the same line to indicate status, e.g.
>
> <time1> thinking.
> <time2> thinking..
> <time3> thinking...
>
> If I use
> print "thinking.";
> then
> print ".";
> then finally
> print "\n";
>
> Nothing shows up on my xterm until the \n line. Any suggestions?
I must assume that since you are using xterm, you are on a Unix-ish
machine....
>From my understanding, most Unix-ish machines buffer output. What is
probably happening is that the buffer is not filling, so nothing is being
output. My test script did the same thing you stated. No output until the
"print \n" line. (Actually, probably no output until EOJ, or close of
filehandle).
Before you print anything to (I'm assuming STDOUT), do this:
select(STDOUT); # Select STDOUT as your default output
$| = 1; # (<--- = dollar-sign pipe) Force
non-buffered output
print "thinking";
.
.
.
That should do what you want.
Dave
>
>
> please cc: to dradams@bigfoot.com
As requested.
> Thanks ahead of time!
>
Enjoy.
--
"Security through obscurity is no security at all."
-comp.lang.perl.misc newsgroup posting
------------------------------------------------------------------------
* Dave Barnett U.S.: barnett@houston.Geco-Prakla.slb.com *
* DAPD Software Support Eng U.K.: barnett@gatwick.Geco-Prakla.slb.com *
------------------------------------------------------------------------
------------------------------
Date: Fri, 5 Dec 1997 10:25:02 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: printing and screen output
Message-Id: <us9966.hn1.ln@localhost>
David Adams (blue145@u.washington.edu) wrote:
: I didn't find the answer to this question in the FAQ.
Thanks for looking before posting.
We all appreciate that.
: Nothing shows up on my xterm until the \n line. Any suggestions?
Output is normally buffered.
With 'line buffered' output, the buffer is flushed when a 'line'
is buffered (ie. when a newline is put into the buffer).
You want to 'flush' the buffer earlier than that.
Once you know that the 'puter nerd terms for your problem are
"buffer" and "flush", the Perl FAQ (part 5) easily provides the answer:
"How do I flush/unbuffer a filehandle? Why must I do this?"
[ this is the very first question in the FAQ that deals with
files and formats... ]
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 05 Dec 1997 11:30:41 -0800
From: jlee <jlee@mdsi.bc.ca>
Subject: Problem with function call to ps()
Message-Id: <34885661.69FE@mdsi.bc.ca>
I want to a process which keeps checking whether a process is running
and find out the number of instances of that process. I made a test
process called qcom which just has a infinite while loop to
sleep for 200000000000 seconds. Most of the time, ps("x") would
work correctly; however, sometimes ps("x") would not return anything
lines containing qcom and I checked that qcom is still running. When
I run more qcom processes, this problem becomes more noticeable.
The following code is the body (simplified) of the process to check
for qcom. It is process forked from a main program.
I am using perl 5.001 on a AIX machine.
sub chk_qcom
{
use Shell qw(ps);
my($line,$qcom_count,$ps_info);
while (1) {
$qcom_count = 0;
@ps_info = split(/\n/,ps("x"));
foreach $i (0..$#ps_info) {
if ($ps_info[$i] =~ /qcom/) {
print("$ps_info[$i]\n"); #for debugging
$qcom_count++;
}
}
sleep(2);
}
}
In different version of chk_qcom, I used open(psfd, "ps x | grep qcom
|")
instead of ps("x") and had the same problem. But, if I add sleep(2)
right after calling open(psfd, "ps x | grep qcom |"), it seems to work.
Any ideas? Are there any other alternatives to calling ps("x") and
open(psfd, "ps x | grep qcom |") such as a direct system call?
Thanks in advance.
Jerry
jlee@mdsi.bc.ca
------------------------------
Date: Fri, 05 Dec 1997 13:03:19 -0600
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
Subject: Re: Question about the =~ operator
Message-Id: <34884FF5.CEBD7593@houston.Geco-Prakla.slb.com>
Richard C. Herselman wrote:
> Hey y'all I was wondering if it's possible to match one string with
> another without using the match operator (=~), because when I use the
> match operator, like this: if ($somestring =~ /abc/) { # or
> whatever something; something; something;}
The above is exactly correct. The fact that it is not working leads me
to believe 1 of 2 things:
1. The above is not what your code really looks like (I'm sure the
above is not actually the code), or
2. You have a very odd implementation of Perl.
if ($somestring =~ /abc/) {
print "Got it!\n";
} else {
print "Don't got it!\n";
}
Will work fine, assuming that $somestring really does have abc in it.
My first thought is that you have :
if ($sometring = /abc/) { and are getting nothing. That's what
I get when I try this. $somestring gets magically unset.
Also, do you have "/usr/local/bin/perl -w" at the beginning of your
script? The "-w" portion prints warning messages.....
HTH
Dave
--
"Security through obscurity is no security at all."
-comp.lang.perl.misc newsgroup posting
------------------------------------------------------------------------
* Dave Barnett U.S.: barnett@houston.Geco-Prakla.slb.com *
* DAPD Software Support Eng U.K.: barnett@gatwick.Geco-Prakla.slb.com *
------------------------------------------------------------------------
------------------------------
Date: 5 Dec 1997 18:33:18 GMT
From: kehoe@fc.hp.com (Jeff Kehoe)
Subject: replacement for fork() on NT?
Message-Id: <669hde$7vo@fcnews.fc.hp.com>
Has anybody found a good 0 for fork() on NT? I realize that
it isn't supported on NT, but wondered what people are doing in its
place on NT.
Thanks in advance for the help,
Jeff Kehoe
------------------------------
Date: Fri, 5 Dec 1997 11:48:33 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Mark Imel <mark@seattlelab.com>
Subject: Re: Returning Values from a Perl script
Message-Id: <Pine.GSO.3.96.971205114713.29415B-100000@usertest.teleport.com>
On Thu, 4 Dec 1997, Mark Imel wrote:
> I'm not sure how to return a value (or address) from my perl script,
> which was activated by the embedded perl interpreter from my c program.
Does the perlembed manpage point you in the right direction? Hope this
helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Fri, 5 Dec 1997 12:32:17 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Kitty Smith <smith@twsuvm.uc.twsu.edu>
Subject: Re: searching indexed file
Message-Id: <Pine.GSO.3.96.971205123047.29415J-100000@usertest.teleport.com>
On Thu, 4 Dec 1997, Kitty Smith wrote:
> I am looking for a more efficient way of searching an indexed file
> than using regular expressions.
If it's an indexed file, look in the index. If you're not sure how to do
that, check the docs for the file format. If the docs are insufficient,
contact the author. Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Fri, 05 Dec 1997 15:51:51 -0500
From: Ty Cage Warren <tycage@infi.net>
Subject: Re: Seems to be just another 5.004_* bug:-(
Message-Id: <34886967.1E079F2F@infi.net>
Brandon S. Allbery KF8NH; to reply, change void to kf8nh wrote:
>
> In <Pine.GSO.3.96.971204141220.4421N-100000@usertest.teleport.com>, on
> 12/04/97 at 02:14 PM,
> Tom Phoenix <rootbeer@teleport.com> said:
> +-----
> | for ($n=1; $n < 1e12; $n++) { sleep 1 }
> | What do you propose that we do about it? :-)
> +--->8
>
> "I can't allow you to do that, Dave." :-) A sentient Perl is about the only
> evolution path left anyway....
Just what I need.... A Perl that will look at my old code and respond:
"HAHAHAHAHAHAHAHAHAHAHAHAHAHA, I can't believe you actually wrote that."
It's bad enough when *I* look at my old code. =)
Ty "or my new code" Warren
--
+---+
Ty Cage Warren tycage@infi.net
Systems Engineer InfiNet
The Web Site of Love: http://www.wsol.net/mst3k/
PGP Public Key: http://tazer.engrs.infi.net/~tycage/pgpkey.html
PGP Fingerprint: FF C1 28 CA 80 B5 31 78 B1 24 2E 8C AB DA FB D2
------------->Never invoke anything bigger than your head.<-------------
------------------------------
Date: Fri, 5 Dec 1997 11:43:55 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: charlot@SPAM-FREE.org
Subject: Re: Setting default printer under Windows NT
Message-Id: <Pine.GSO.3.96.971205114230.29415A-100000@usertest.teleport.com>
On 4 Dec 1997 charlot@SPAM-FREE.org wrote:
> is there a way to change the default printer from Perl under
> Windows NT ? Or to change the page layout of a printer ?
If there is a way, it's not specific to Perl. Check with the docs for your
printer; if you can do this, it's done by editing a file or running a
command, or something like that. If you can't find what you need there,
try a newsgroup about your operating system. But it's not a Perl problem.
Good luck!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Fri, 5 Dec 1997 15:41:19 -0500
From: "Dave Kaufman" <davidk@nospam.cnct.com>
Subject: Re: the skinny on my() vs local() - thanks to all
Message-Id: <669pr8$8cc@world6.bellatlantic.net>
Faust Gertz wrote in message <34880cb0.2411484@news.wwa.com>...
>On Thu, 4 Dec 1997 13:45:06 -0500, "Dave Kaufman"
><davidk@nospam.cnct.com> wrote:
>
>>What is the difference between my() and local() ?
>>Can someone lend me a clue?
>>
> [much humorous humor snipped]
>
>Ok, enough. Here is what the FAQ has to say....
>
>[what the faq had to say snipped as well]
>
>Faust Gertz
>Philosopher at Large
Many thanks to all for a deluge of email (especially Tom Christiansen's 18K
response :-)) that answered this question for me shortly, longly,
realisticly, theoretically and humorously.
The answer (the skinny) for me was,
"No, silly. You can't go changing other people's local's to my's for 2
reasons."
1: my declares new variables and local scopes existing ones.
2.: locally scoped variables stay in scope into nested subroutine calls.
My-declared variables cease to exist outside of their home turf code block,
thus exposing any globals of the same name.
So, for my situtaion, where I was moving a bunch of Matt Wright's cookbook
routines (great book, get it!) into my programs, I would not have wanted to
change the local's to my's because they were there so that one of his
routines could call another of his routines and keep scope.
- Dat be da skinny :-)
Thanks again, Perlilians. You guys are da bomb.
------------------------------
Date: Fri, 5 Dec 1997 15:43:34 -0500
From: "Dave Kaufman" <davidk@nospam.cnct.com>
Subject: Re: the skinny on my() vs local() - thanks
Message-Id: <669pvk$8tc@world6.bellatlantic.net>
Faust Gertz wrote in message <34880cb0.2411484@news.wwa.com>...
>On Thu, 4 Dec 1997 13:45:06 -0500, "Dave Kaufman"
><davidk@nospam.cnct.com> wrote:
>
>>What is the difference between my() and local() ?
>>Can someone lend me a clue?
>>
> [much humorous humor snipped]
>
>Ok, enough. Here is what the FAQ has to say....
>
>[what the faq had to say snipped as well]
>
>Faust Gertz
>Philosopher at Large
Many thanks to all for a deluge of email (especially Tom Christiansen's 18K
response :-)) that answered this question for me shortly, longly,
realisticly, theoretically and humorously.
The answer (the skinny) for me was,
"No, silly. You can't go changing other people's local's to my's for 2
reasons."
1: my declares new variables and local scopes existing ones.
2.: locally scoped variables stay in scope into nested subroutine calls.
My-declared variables cease to exist outside of their home turf code block,
thus exposing any globals of the same name.
So, for my situtaion, where I was moving a bunch of Matt Wright's cookbook
routines (great book, get it!) into my programs, I would not have wanted to
change the local's to my's because they were there so that one of his
routines could call another of his routines and keep scope.
- Dat be da skinny :-)
Thanks again, Perlilians. You guys are da bomb.
------------------------------
Date: Fri, 5 Dec 1997 12:57:13 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Hans Van Lint <hvanlint@lodestar.be>
Subject: Re: validation problem
Message-Id: <Pine.GSO.3.96.971205124752.29415N-100000@usertest.teleport.com>
On Fri, 5 Dec 1997, Hans Van Lint wrote:
> Can someone explain me why this doesn't work?
Maybe; what's it supposed to do? :-)
> Someone fills in a form and the following data is beeing sent,
> 15
> 100
> LDSFK,
>
> # checken of integer
> $i = 0;
> $geenint = 0;
>
> foreach $veld (%input){
That's not the usual way to go through a hash. This is iterating over each
key and value separately: If it's a three-element hash, you'll loop six
times. I think you probably want to use keys(), then look at each value
just once.
> if (($i+2) % 2 != 0){
Is this a way to look at only the values?
> $response = ($veld =~ /^[+-]?\d+$/) ? "OK" : "NO";
> if ($response eq "NO"){ $geenint = 1;}
> $i++;
> }}
>
> if ($geenint == 1){
> print "Please fill in numbers only. Go back and correct your data.<P>";
> }
> else
> {
> #continue with program
> }
I think you could do what you want with code like this.
my $geenint;
for (keys %input) {
next if $input{$_} =~ /^[+-]?\d+$/;
$geenint = $input{$_};
last;
}
if (defined $geenint) {
# bad input, which is copied to $geenint
# output some error message, possibly using $geenint
exit;
}
# rest of program goes here.
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Fri, 05 Dec 1997 10:36:12 -0800
From: Jim Bowlin <bowlin@sirius.com>
To: Scott Cairns <sdcairns@mindspring.com>
Subject: Re: Win32-Perl: How to get location of NT system directory?
Message-Id: <3488499C.EF0C56DE@sirius.com>
Scott Cairns wrote:
>
> Subject says it all? I need to Win32:Spawn() an executable in the
> Winnt/system32 directory but I cannot guarantee that this directory is
> either called "winnt" or is on the user's C: drive. How can I find out the
> root directory where NT (4.0) is installed?
try $ENV{windir}
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 1425
**************************************