[9112] in Perl-Users-Digest
Perl-Users Digest, Issue: 2730 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 26 19:07:35 1998
Date: Tue, 26 May 98 16:01:43 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 26 May 1998 Volume: 8 Number: 2730
Today's topics:
Question about four-argument select use elvi@dsuper.net
Re: reference to tom c's filehandles tutorial <rootbeer@teleport.com>
Re: regexp to delete trailing spaces? <lanier@shell6.ba.best.com>
Re: regexp to delete trailing spaces? <khaines@oshconsulting.com>
Re: regexp to delete trailing spaces? (Craig Berry)
Re: regexp to delete trailing spaces? <rootbeer@teleport.com>
Re: SECURITY - simple perlscript for taking orders (brian d foy)
SendKeys jstephan@my-dejanews.com
Re: software dictatorship <vonbrand@inf.utfsm.cl>
The RPC server is unavailable <Tom_Howland@notes.pw.com>
uploading files <webmaster@directnet.com>
Re: utility which can POST web queries (Jonathan Stowe)
Re: while, each & assoc array (John Porter)
Re: Why does this expr {...} get memory fault? <rootbeer@teleport.com>
Re: Writing to a file <rootbeer@teleport.com>
Re: Xor computation <rootbeer@teleport.com>
Re: Xor computation <tchrist@mox.perl.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 26 May 1998 22:01:35 GMT
From: elvi@dsuper.net
Subject: Question about four-argument select use
Message-Id: <6kfe3v$2qo$1@nnrp1.dejanews.com>
I'm trying to write a script which will connect via Sockets to a specified TCP
server, send and receive some
standard protocols from said server, and then fork so that it can send data
and receive data simultaneously, reading
from and writing to files. I have been hacking away at this, adding bits and
pieces from faqs, manuals, books, and
the newsgroup, and I've reached a point now where I'm not sure what's wrong,
but it doesn't work.
My first question concerns the four argument select: the examples in the Camel
book I find quite cryptic, as I'm new
to perl. What I want to do is write lines of text (from the input file) to the
socket whenever the socket is ready
for input, until I run out of lines, at which point I have to write a zero to
the socket and close the writing fork.
I also want to read from the socket whenever it's ready to be read from, until
I read a zero on a line by itself. I
do understand that I have to use sysread and syswrite, not buffered functions.
Here's some of my code:
sub getreturncode
{
my($rin, $nfd) = ("",""); # initialize variables
vec($rin, fileno(SOCKET), 1) = 1; # construct bitmask
if ($nfd = select($rin, undef, undef, 2)) { # check if SOCKET is ready
$code = readline; # if so, read from it (see sub readline)
$desc = readline;
($code =~ /200/) ? print "$code$desc\n" : die $desc;
}
else { # if not, die.
die "timed out waiting for socket to be read-ready\n";
}
}
# read a line at a time without using buffered functions;
# lifted wholesale from code in this newsgroup.
sub readline
{
my ($someleft, $ch, $line) = (1, '', '');
while($someleft && $ch ne "\n") {
$someleft = sysread(SOCKET,$ch,1);
$line .= $ch;
}
return $line;
}
I hope this is enough of a sample if some kind soul decides to try to
enlighten me. I don't want to overload the group with the whole messy script.
The problem right now is that I never receive a go-ahead to read from select.
When I was doing this without select, using regular buffered <> function to
read, I did get data from the socket, so I know it's possible. Just not sure
what I'm doing wrong. I hope it's obvious to someone else.
Thanks in advance for any help you can give.
Elvi Dalgaard
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Tue, 26 May 1998 17:38:52 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: reference to tom c's filehandles tutorial
Message-Id: <Pine.GSO.3.96.980526103546.27437I-100000@user2.teleport.com>
On Tue, 26 May 1998, matthew d. p. k. lanier wrote:
> about 3 weeks ago tom c posted an enlightening tutorial on using globs
> to pass filehandles around in a much quicker way than using the
> FileHandle module.
>
> if anyone has a copy of that, could you please reforward it to me, or
> repost it?
>
> i'm sorry for the wasted bandwidth.
There are a number of Usenet archives around; wouldn't one of those have
the document, give it to you more quickly than anyone here could, and not
use any Usenet bandwidth in the process? (If you don't have direct web
access, that's another matter. In that case, let me know by private email;
I'll help you get information on accessing the web via email or another
way.)
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 26 May 1998 14:54:53 -0700
From: "matthew d. p. k. lanier" <lanier@shell6.ba.best.com>
Subject: Re: regexp to delete trailing spaces?
Message-Id: <Pine.BSF.3.96.980526145331.18784B-100000@shell6.ba.best.com>
ross-
my $foo = 'all that glitters ';
$foo =~ s/\s*$//;
this should do the trick...
matt lanier
matt@lanier.org
matt@saturn5.com
On Tue, 26 May 1998, Ross Yahnke wrote:
> Hi all - A newbie question here, what's a useful regexp to delete all the
> trailing spaces in a string?
>
> I.e., I want to change:
> "All that glitters "
>
> ...to...
> "All that glitters"
------------------------------
Date: Tue, 26 May 1998 16:09:17 -0600
From: "Kirk D. Haines" <khaines@oshconsulting.com>
To: Ross Yahnke <rcyahnke@doit.wisc.edu>
Subject: Re: regexp to delete trailing spaces?
Message-Id: <6kfdur$1nr$1@gte1.gte.net>
Ross Yahnke wrote:
>
> Hi all - A newbie question here, what's a useful regexp to delete all the
> trailing spaces in a string?
>
> I.e., I want to change:
> "All that glitters "
>
> ...to...
> "All that glitters"
>
> Thanks in advance!
$a = "All that glitters ";
print "|$a|\n";
$a =~ s/\s*$//;
print "|$a|\n";
When run:
|All That Glitters |
|All That Glitters|
Note that this deletes all trailing whitespace. To specifically delete
only
all trailing spaces, change the regexp to be:
s/ *$//;
Kirk Haines
------------------------------
Date: 26 May 1998 22:12:09 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: regexp to delete trailing spaces?
Message-Id: <6kfenp$mu$2@marina.cinenet.net>
Ross Yahnke (rcyahnke@doit.wisc.edu) wrote:
: Hi all - A newbie question here, what's a useful regexp to delete all the
: trailing spaces in a string?
This is a FAQ; it's answered in the documentation that came with your
distribution of Perl. Asking FAQs here will do permanent Bad Things to
your reputation on clpm. Read the FAQ. The FAQ is your friend.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Tue, 26 May 1998 21:19:01 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: regexp to delete trailing spaces?
Message-Id: <Pine.GSO.3.96.980526141837.27437o-100000@user2.teleport.com>
On Tue, 26 May 1998, Ross Yahnke wrote:
> what's a useful regexp to delete all the
> trailing spaces in a string?
The one in the FAQ is pretty good. :-)
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 26 May 1998 18:20:54 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: SECURITY - simple perlscript for taking orders
Message-Id: <comdog-ya02408000R2605981820540001@news.panix.com>
Keywords: from just another new york perl hacker
In article <6kf85v$pjp$1@nnrp1.dejanews.com>, nem@aae.com posted:
>I've got it up and running, but am wondering how secure it is. I started w/
>simple mailto: routines, combined with a section that writes to the file. The
>flat file is OUTSIDE of the w3 path, and the email reminder (that says to go
>look at the file to process manually) does NOT contain any sensitive
>information, such as the card type or number or exp. date.
if the flat file stores unencrypted numbers, it's not secure. just ask
NETCOM :)
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers T-shirts! <URL:http://www.pm.org/tshirts.html>
------------------------------
Date: Tue, 26 May 1998 21:50:09 GMT
From: jstephan@my-dejanews.com
Subject: SendKeys
Message-Id: <6kfdeh$1nl$1@nnrp1.dejanews.com>
Hi,
I'm wondering if there's a way to send keystrokes to another application in
Perl on a Win32 system. I've seen it done in an Excel macro with SendKeys().
If the soulution is not standard Perl and I need to download a module, that's
still ok.
Thanks in advance,
-Jon Stephan
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 26 May 1998 17:18:53 -0400
From: Horst von Brand <vonbrand@inf.utfsm.cl>
Subject: Re: software dictatorship
Message-Id: <m1n2c4ohmq.fsf@pincoya.inf.utfsm.cl>
tb@mit.edu (Thomas Bushnell, n/BSG) writes:
> fjh@cs.mu.oz.au (Fergus Henderson) writes:
> > However, if Tom C. should happen to lose it, then what? As far as
> > his documentation goes, then we'd be screwed.
> "Should happen to". "Should happen to".
> I'm still trying to understand the use of the hypothetical here.
Is it *really* needed to get to this low level here?
It's been a _long_ time since I saw such a textbook-example class flamewar:
Much bitter fighting about no real content. TC is free to do as he pleases;
if you or I don't like what he does, too bad. The FSF is free the same way.
Can we leave it at that? Pretty please?
--
Dr. Horst H. von Brand mailto:vonbrand@inf.utfsm.cl
Departamento de Informatica Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria +56 32 654239
Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513
------------------------------
Date: Tue, 26 May 1998 21:25:04 GMT
From: Tom Howland <Tom_Howland@notes.pw.com>
Subject: The RPC server is unavailable
Message-Id: <yfzlnroohcf.fsf@bamboo.i-did-not-set--mail-host-address--so-shoot-me>
I'm doing ole programming from Perl. Its great! I'm using it to generate
Excel charts.
One thing that has me puzzled is the following error message:
OLE error 0x800706ba: "The RPC server is unavailable"
in methodcall/getproperty "Workbooks" at D:\tom\perl\5.00402\lib/perl5db.pl line 65535
Win32::OLE::AUTOLOAD('Win32::OLE=HASH(0xb7d6b0)') called at excel_client.pl line 171
Carp::carp('OLE error 0x800706ba: "The RPC server is unavailable"^J in met...') called at D:\tom\perl\5.00402\lib/perl5db.pl line 65535
Win32::OLE::AUTOLOAD('Win32::OLE=HASH(0xb7d6b0)') called at
excel_client.pl line 171
The statement that starts all this in my source is
my $workbook = $application->Workbooks->Add() || die "couldn't create a workbook: $!";
where $application is created with
my $application = Win32::OLE->new('Excel.Application', 'Quit') || die "couldn't connect to Excel: $!";
I observe that I do not get this error when I always Quit my application
instance after closing my workbook. In other words, the error goes away
if I constantly create and destroy application instances instead of just
keeping on application open and creating and destroying workbooks within
it. This has a very serious performance penalty. If I keep the
application open, chart generation is about half a second. But if I
don't, marshaling causes a several second delay.
Any ideas what is going on?
I'm using windows nt 4 service pack 3, MS Excel 97, perl 5.00402
(prebuilt), and libwin32-0.12 (prebuilt).
------------------------------
Date: Tue, 26 May 1998 14:38:11 -0700
From: Garrick Staples <webmaster@directnet.com>
Subject: uploading files
Message-Id: <356B3642.148E1EB5@directnet.com>
I have an application to use the nifty html file upload feature.
However implementaion has been a bear. I started this project by doing
the form decoding myself, but that became problematic; I can't seem to
find any documentation about the "multipart/form-data" enctype. So then
I looked at the "CGI::BasePlus" module, but can't seem to get that to
work.
I guess my question is "Does anybody have any sample scripts that
upload files?" I don't care if I use the CGI module or not, I just want
the mulitpart/form-data decoded.
Thanks in advance for that certain life saver out there.
-Garrick
------------------------------
Date: Tue, 26 May 1998 22:07:07 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: utility which can POST web queries
Message-Id: <356af939.7775951@news.btinternet.com>
On Tue, 26 May 1998 12:19:00 -0400, Jonathan Epstein wrote :
>I am currently using url_get.pl to perform remote web processing in a
>CGI script.
> http://dan.hcf.jhu.edu/ftp/Perl/
>Unfortunately, it is only capable of handling the get protocol, and many
>of remote sites which I'm using require the post protocol. Which
>utility should I using (preferably one which is commonly used by
>others)?
>
Your weapon of choice here will be libwww-perl (LWP) available from
CPAN which will enable you to construct requests of all types. There
is good documentation and examples with the distribution.
If you want to roll your own POSTing code you will need to check out
the HTTP and CGI specifications. (see the sig for links).
/J\
back with Frankenstein's monster hand and fixed computer.
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Tue, 26 May 1998 20:59:34 GMT
From: jdporter@min.net (John Porter)
Subject: Re: while, each & assoc array
Message-Id: <MPG.fd4f90c662e88e49896ef@news.min.net>
On 26 May 1998 17:16:11 GMT,
in article <6ketcr$cu$1@coranto.ucs.mun.ca>,
pdf@morgan.ucs.mun.ca (Paul David Fardy) wrote:
>
>....
> That's the beauty of indentation. It does not say "Look at me!".
> Just the opposite: it silently says "Look: these lines are a block. -->"
>
> It's my belief that the braces provide little to the human reader
> that isn't better provided by sensible indentation. Both the code
> samples above are quite clear to me because I rely on the indentation
> to reflect the semantics of the code.
>....
So I take it you're a fan of Python?
John Porter
------------------------------
Date: Tue, 26 May 1998 21:18:10 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Why does this expr {...} get memory fault?
Message-Id: <Pine.GSO.3.96.980526140908.27437n-100000@user2.teleport.com>
On Tue, 26 May 1998, John Chambers wrote:
> eval {
> local $SIG{'ALRM'} = sub {die "connect timed out\n"};
> alarm($HTTPtimeout);
> $connstat = connect(F,$that);
> };
> if ($@) {
> ...
> }
>
> I can show by adding calls of print before and after the eval block
> that the code goes into the eval and doesn't come out.
Well, every signal handler written in Perl can potentially fail by being
triggered at a bad time. It looks as if, on your system, a signal during
the connect call comes at a bad time. :-(
> Is this a problem that has been faced before? Is there maybe a patch
> for it lying about somewhere?
A proposed solution exists, but it was vetoed by Larry because it would
have slowed Perl by about 3% or so, whether you use signals or not. That
could be improved, though. If no other way, it could be improved by buying
newer hardware. :-)
The workaround in your case would probably involve writing an XSUB to do
the job. That's not terribly difficult, but it's not trivial either. Good
luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 26 May 1998 19:39:33 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Writing to a file
Message-Id: <Pine.GSO.3.96.980526123904.27437O-100000@user2.teleport.com>
On 26 May 1998, Alexandr Dubovikov wrote:
> open(DATABASE, ">>records.dat");
Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.
Thanks!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 26 May 1998 19:38:11 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Xor computation
Message-Id: <Pine.GSO.3.96.980526121813.27437N-100000@user2.teleport.com>
On Tue, 26 May 1998, Gai Hetzroni wrote:
> I have a perl program that needs to Xor all bytes in an array (which is
> very large one)
> The input file is made of lines with the following format:
>
> 0xHH, 0xHH, 0xHH ...
>
> where H is a hexadecimal digit.
>
> $Xor =~ s/,/^/g;
> $result = eval $Xor;
Eeeek! 'eval' on strings should have been named 'evil'. Well, it's not
always evil, but it can easily be misused and abused, as it was here.
Assuming that your input is as you say, here's one way to do it. I'm sure
it's not the fastest, but it should do the job.
# Input lines may or may not have trailing commas
# The result from this input should be 72 = 0x48
my $input = q{
0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61,
0x6e, 0x20, 0x41, 0x53, 0x43, 0x49, 0x49, 0x20, 0x73
0x74, 0x72, 0x69, 0x6e, 0x67, 0x2c, 0x20, 0x79, 0x6f
0x75, 0x20, 0x63, 0x75, 0x72, 0x69, 0x6f, 0x75, 0x73,
0x20, 0x70, 0x65, 0x72, 0x73, 0x6f, 0x6e, 0x21
};
my $result = 0;
for (split /\n/, $input) { # or a while loop, reading it in
for (split /\W+/) {
$result ^= hex $_; # assuming valid hex byte!
}
}
print "The answer is $result\n";
Now, having said that... You _do_ realize that xor-ing bytes like this is
a very weak replacement for a true CRC or checksum, don't you? But we can
hope that that's not what you're trying to do.
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 26 May 1998 22:22:28 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Xor computation
Message-Id: <6kffb4$c4h$3@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Tom Phoenix <rootbeer@teleport.com> writes:
:Now, having said that... You _do_ realize that xor-ing bytes like this is
:a very weak replacement for a true CRC or checksum, don't you? But we can
:hope that that's not what you're trying to do.
Maybe he'd rather do:
$a ^= $b;
$b ^= $a;
$a ^= $b;
as an easier to read substitute for
($a, $b) = ($b, $a);
--tom
--
sum to check equivalent files should use sum -a. --Andrew Hume
------------------------------
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 2730
**************************************