[8892] in Perl-Users-Digest
Perl-Users Digest, Issue: 2509 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 5 19:17:27 1998
Date: Tue, 5 May 98 16:00:26 -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, 5 May 1998 Volume: 8 Number: 2509
Today's topics:
Re: #PERL the IRC Channel on Efnet. <rra@stanford.edu>
Re: 'C' command "TOUPPER" or "TOLOWER". <andrewf@cp.pathfinder.com>
autoflush or $| <rar@rentrak.com>
Re: Calling another script... <andrewf@cp.pathfinder.com>
Re: Calling another script... <tchrist@mox.perl.com>
Re: cgi-lib.pl or CGI.pm? <ag-ho@students.uiuc.edu>
Re: cgi-lib.pl or CGI.pm? (brian d foy)
Condition to subroutine <graham@contact.com.au>
Re: COUNTING DAYS UNTIL 2000 (Hakan Hjelmstrom)
Re: CPAN & Module gripes (was Re: Ever Wonder...?) (Stuart McDow)
Re: deleting lines from file help (Douglas Wilson)
Re: Embedded systems programming (Craig Berry)
Re: Ever Wonder Why Not Everyone Uses Modules? <rra@stanford.edu>
Expect / DynaLoader error? (Dave Haywood)
Re: How to send email (was Re: Ever Wonder Why Not Ever <rra@stanford.edu>
IO::Sockets, Sample code needed johnvv@earthling.net
Re: IO::Sockets, Sample code needed <tchrist@mox.perl.com>
IS THIS POSSIBE IN PERL! (Keith Woodman)
Re: IS THIS POSSIBE IN PERL! (brian d foy)
Re: Newbie Q: access file handles in a subroutine? (Hakan Hjelmstrom)
Re: Using executable pathname to define include path <David.Boyce@fmr.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 05 May 1998 15:42:07 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: #PERL the IRC Channel on Efnet.
Message-Id: <m3vhrkcpc0.fsf@windlord.Stanford.EDU>
Take it to alt.irc or something, guys. They get off on this stuff. The
rest of us really could care less.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Tue, 5 May 1998 18:02:50 -0400
From: "Andrew F. Lee" <andrewf@cp.pathfinder.com>
Subject: Re: 'C' command "TOUPPER" or "TOLOWER".
Message-Id: <Pine.GSO.3.95.980505180154.18176D-100000@cp.pathfinder.com>
On Sun, 3 May 1998, University Student wrote:
> Does anyone know what the alternative to the "C" command
> toupper (x);
> is in Perl?
$x = uc($y);
-------------------------------------------------------------
Andrew F. Lee | |
Software Engineer | parenttime.com |
email: andrewf@pathfinder.com | 1271 Avenue of the Americas |
Phone: (212) 522-2769 | New York, N.Y. 10020 |
-------------------------------------------------------------
When I say, "Ignore the man behind the curtain."
That is because there is no man behind the curtain.
------------------------------
Date: Tue, 5 May 1998 15:36:18 -0700
From: "Richard Robinson" <rar@rentrak.com>
Subject: autoflush or $|
Message-Id: <6io3vt$suc$1@brokaw.wa.com>
Hello,
I've got a CGI script that runs an LWP client. I want to log the results of
the client's success (or not) to a log file and AT the same time (or
thereabouts in milliseconds) I want to print the results to STDOUT, or my
browser.
I've done this, basically,
open TEMP "log.file"
select TEMP
autoflush(1);
select STDOUT
autoflush(1);
But the autoflush is not working on the STDOUT (I don't know if it's working
on TEMP either, but don't really care). What happens is that after a while
the browser I'M IN, says that it doesn't receive a response from the server,
and I click on OK (only option). So my connection is closed with server, but
the autoclient continues to run on the server till it is done (fine).
Question is Why isn't autoflush working on STDOUT?
Please EMAIL me as well as reply to this group.
Thank you,
-- Richard Robinson
rar@rentrak.com
------------------------------
Date: Tue, 5 May 1998 18:01:36 -0400
From: "Andrew F. Lee" <andrewf@cp.pathfinder.com>
Subject: Re: Calling another script...
Message-Id: <Pine.GSO.3.95.980505175819.18176C-100000@cp.pathfinder.com>
On Sun, 3 May 1998, University Student wrote:
> I use a complicated Perl Script for a BBS. I need to put a randomizzed
> ad graphix on each time someone views a message on the BBS. I know where
> to insert the script, but it doesn't work.
>
> print "<!--exec:ads.cgi-->";
>
> does not work. So I try to call the AD script :
>
> $something = ../../ads/ad.cgi;
> print " $something ";
>
>
> and all that is printed on the screen via the browser
> is some 5 digit number... Not the actuall add....
> I am so frustrated with this!
I am not sure I understand your problem. Is this a server side include in
an html document?
<!--#exec cgi="ads.cgi"--> does not work?
have you tried :
print `../../ads/ad.cgi`;
-------------------------------------------------------------
Andrew F. Lee | |
Software Engineer | parenttime.com |
email: andrewf@pathfinder.com | 1271 Avenue of the Americas |
Phone: (212) 522-2769 | New York, N.Y. 10020 |
-------------------------------------------------------------
When I say, "Ignore the man behind the curtain."
That is because there is no man behind the curtain.
------------------------------
Date: 5 May 1998 22:21:56 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Calling another script...
Message-Id: <6io3e4$orq$1@csnews.cs.colorado.edu>
In comp.lang.perl.misc,
University Student <i_hate_spam@spam-sucks.com> writes:
:I know where
:to insert the script, but it doesn't work.
:
:print "<!--exec:ads.cgi-->";
:
:does not work.
I could tell you why, Mr i_hate_spam@spam-sucks.com, but I won't.
--tom_hates_ads@ads_suck.com
--
Tom Christiansen tchrist@jhereg.perl.com
> (It's sorta like sed, but not. It's sorta like awk, but not. etc.)
Guilty as charged. Perl is happily ugly, and happily derivative.
--Larry Wall in <1992Aug26.184221.29627@netlabs.com>
------------------------------
Date: Tue, 5 May 1998 17:09:46 -0500
From: Andrew Ho <ag-ho@students.uiuc.edu>
Subject: Re: cgi-lib.pl or CGI.pm?
Message-Id: <Pine.SOL.3.96.980505170717.21804B-100000@ux9.cso.uiuc.edu>
Hello,
<laugh> I still use cgi-lib.pl, but it is mainly because I am lazy and
haven't yet bothered downloading and learning CGI_Lite.pm... but, since I'm
familiar with it, I wanted to point out:
BW>While cgi-lib.pl is kind of outdated, the only thing it won't do is
BW>file upload.
Not quite true; from the documentation:
"Version 2.15 is the latest released version of cgi-lib.pl. New features
in version 2 include support for file upload, improved robustness, and
aids for debugging."
BF>if you prefer to use ancient technology, it's completely up to you.
BF>make sure that you use Mosaic to test your scripts, though.
Actually, I take it as a serious design goal to make my scripts output HTML
that is as browser-independent as practical. IMO, it is a Good Idea to plan
for ancient technology from the user end. Forward thinking is all well and
good but when your users might be running Lynx...
BW>CGI.pm is hideously bloated and combines CGI, HTML, cookies, etc in one
BW>module...which I think is a mistake (Print works very well for HTML
BW>generation...Do I really need an anchor object?)
BW>
BW>use what works for you because 'there is more than one way to do it'
I agree with the misplacement of functionality--I usually have a separate,
site-specific HTML library anyway; why should a module called CGI provide
HTML functionality, anyway? If it is a small script and (extreme)
portability is an issue, I just write my own, 20-lines or so of CGI parsing
code...
LZ>All these things are true about CGI.pm, but I just ran a quick
LZ>benchmark, and CGI.pm is quite a bit slower than cgi-lib.pl
Interesting result. I was going to post to ask about this before--is there
benchmark information as to how much it costs to load multiple modules,
versus just code inclusion via "require" or whatnot? This is often an
issue with scripts running on older machines with less memory.
Any pointers to this information would be appreciated...
Humbly,
Andrew
-------------------------------------------------------------------------
'Twas brillig, and the slithy toves Andrew Ho
Did gyre and gimble in the wabe. ag-ho@uiuc.edu
All mimsy were the borogroves,
And the mome raths outgrabe. http://www.uiuc.edu/ph/www/ag-ho/
-------------------------------------------------------------------------
------------------------------
Date: Tue, 05 May 1998 18:19:19 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: cgi-lib.pl or CGI.pm?
Message-Id: <comdog-ya02408000R0505981819190001@news.panix.com>
Keywords: from just another new york perl hacker
In article <Pine.SOL.3.96.980505170717.21804B-100000@ux9.cso.uiuc.edu>, Andrew Ho <ag-ho@uiuc.edu> posted:
>BF>if you prefer to use ancient technology, it's completely up to you.
>BF>make sure that you use Mosaic to test your scripts, though.
>
>Actually, I take it as a serious design goal to make my scripts output HTML
>that is as browser-independent as practical. IMO, it is a Good Idea to plan
>for ancient technology from the user end. Forward thinking is all well and
>good but when your users might be running Lynx...
gees, does anybody get the joke? i guess most people weren't around
back then.
--
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 <URL:http://www.pm.org>
------------------------------
Date: Wed, 06 May 1998 08:45:00 +1000
From: Graham Wallace <graham@contact.com.au>
Subject: Condition to subroutine
Message-Id: <354F966C.28649B75@contact.com.au>
Thanks, to all those that responded.
The answer as to why my script wasn't working was that I had put in "If"
instead of "if" in one place. The couple of other things like the ";"
omited were just my typing it on to the request for help I thought the
problem I had was more conceptual as this is the first time I had gone
to a subroutine as a result of a condition. Like all things the
simplest typo can cause a headache especially when you try to find the
problem and read what should be there and not what is actually there.
Again thanks to all
time to put this topic to bed!!!!
Graham
------------------------------
Date: Tue, 05 May 1998 21:52:34 GMT
From: hawk@algonet.se (Hakan Hjelmstrom)
Subject: Re: COUNTING DAYS UNTIL 2000
Message-Id: <354f89a4.26682567@news.algonet.se>
On 5 May 1998 20:01:51 GMT, "Mathijs Oosterom" wrote:
> Does anyone has a Perl-script that counts the days until the year 2000?
> Or does anybody know how to do that? Is there a function that gives a value
> in days for each given date?
Haven't used it myself yet, but look at the documentation for
Date::manip.
Hekan Hjelmstrvm
hawk@algonet.se
------------------------------
Date: 5 May 1998 22:17:29 GMT
From: smcdow@arlut.utexas.edu (Stuart McDow)
Subject: Re: CPAN & Module gripes (was Re: Ever Wonder...?)
Message-Id: <6io35p$j0k$1@ns1.arlut.utexas.edu>
cpierce1@cp500.fsic.ford.com (Clinton Pierce) writes:
>
> The problem is that I'm behind _VERY_ thick firewalls here. I'm
> going through HTTP proxies, FTP bastion-hosts and internal newsfeeds
> to hear anything about Perl.
My apologies. I hate to bring personal preference into this, but I
could never work in such an environment. But the difference in our
networking environments probably does get to the heart of the
ease/difficulty conundrum.
> The "automagic" approach makes a lot of assumptions about your current
> networking environment, which aren't necessarily true. And between
> having no CPAN and automagic CPAN, there's a lot of crap.
That's probably true. It seems to me that the CPAN and CPAN.pm were
meant to be used together - and that it would indeed be difficult to
use the CPAN without CPAN.pm. They seem to have been designed
concurrently. Moreover, CPAN.pm probably assumes that you have at
least as much as ftp access to the local CPAN site (a resonable
assumption for 85% of machines out there, I'd wager). I've never tried
to download and install a module via ftp or the web., so I can't
comment on how hard that is to do.
> I'm grateful for CPAN, in any shape. Yes, people going about Hard
> Tasks by using stone knives and bearskins really need to be told to
> about CPAN. Their Questions should be answered as well. Right now,
> if a "module newbie" asked me about the MIME stuff I used as an
> example earlier, I'd have to answer: "You might want to try the
> MIME::Parser module on CPAN. it might be part of libwww, or it
> might be in mime-tools. I dunno. It's not really that well
> documented. But if you get too frustrated, and this is a throwaway
> piece of code, take a look at RFC...."
% perl -MCPAN -eshell
cpan shell -- CPAN exploration and modules installation (v1.36)
ReadLine support enabled
cpan> i /mime/
Distribution ERYQ/MIME-Lite-1.123.tar.gz
Distribution ERYQ/MIME-tools-4.116.tar.gz
Distribution GAAS/MIME-Base64-2.05.tar.gz
Module MIME::Base64 (GAAS/MIME-Base64-2.05.tar.gz)
Module MIME::Body (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::Decoder (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::Decoder::Base64 (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::Decoder::Binary (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::Decoder::Gzip64 (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::Decoder::NBit (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::Decoder::PGP (JWIED/Mail-ispmailgate-1.000.tar.gz)
Module MIME::Decoder::QuotedPrint (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::Decoder::UU (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::Entity (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::Field::ConTraEnc (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::Field::ContDisp (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::Field::ContType (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::Field::ParamVal (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::Head (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::IO (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::Latin1 (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::Lite (ERYQ/MIME-Lite-1.123.tar.gz)
Module MIME::Parser (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::ParserBase (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::QuotedPrint (GAAS/MIME-Base64-2.05.tar.gz)
Module MIME::ToolUtils (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::Tools (ERYQ/MIME-tools-4.116.tar.gz)
Module MIME::Words (ERYQ/MIME-tools-4.116.tar.gz)
cpan>
It looks like you'd want some combination of
GAAS/MIME-Base64-2.05.tar.gz and ERYQ/MIME-tools-4.116.tar.gz. Further
research would be required. I actually don't remember what I installed
here.
You know, it'd be a cool little CGI project for someone to set up a
website that uses CPAN.pm to do queries, display readmes, etc.
I'm not gonna do it, though. :-)
--
Stuart McDow Applied Research Laboratories
smcdow@arlut.utexas.edu The University of Texas at Austin
"It is obvious that about 750,000 people ago, Austin was a wonderful City."
------------------------------
Date: Tue, 05 May 1998 22:09:12 GMT
From: dgwilson@gte.net (Douglas Wilson)
Subject: Re: deleting lines from file help
Message-Id: <6io27c$jji$1@gte1.gte.net>
There's probably a better way but here's one:
perl -pi -e '($. <= 20000) and $_="";' logfile
On Tue, 05 May 1998 15:09:20 -0500, robert burditt
<rburditt@london.gos.fedex.com> wrote:
>this should be a fairly simple task, but i cannot figure out
>how to do it... i'd really appreciate any help out there.
>
>i have a log file that grows pretty large and about once a week,
>i'd like to go in and delete the first 20,000 lines or so.
>
>could anyone give insight on how to do this?
>
>thanks a lot,
>robert
>rburditt@fedex.com
------------------------------
Date: 5 May 1998 22:30:38 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Embedded systems programming
Message-Id: <6io3ue$dl1$1@marina.cinenet.net>
Mohammad Razzak (mrazzak@cse.unl.edu) wrote:
: Can anybody enlighten me on the concept of Embedded systems programming?
: Some explanations with examples would be appreciated.
Basically, an 'embedded system' is a computer which operates inside a
specialized piece of equipment performing roles specific to that
equipment, rather than being visible and useable as a general-purpose
computer. Modern flight avionics, the control system in a photocopier,
your car's performance-management computer, and the card readers in
modern hotel door locks are all examples of embedded computer systems.
Embedded systems development is different from 'normal' software
development in several ways. For example:
* Strict real-time processing constraints often apply.
* Memory and processing speed are often severely limited
* Persistent state storage is often *incredibly* limited
* High reliability and fault tolerance are paramount
* Development and testing environments are often cumbersome
due to cross-platform development requirements, and lack
of a UI on the target system
To my knowledge, nobody has ever developed a 'real' embedded application
in Perl -- but I'd love to hear about one, if such exists!
HTH...
---------------------------------------------------------------------
| 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: 05 May 1998 15:39:58 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Ever Wonder Why Not Everyone Uses Modules?
Message-Id: <m3yawgcpfl.fsf@windlord.Stanford.EDU>
Matthew Cravit <mcravit> writes:
> Sure...but when you send mail, you're not necessarily connecting to a
> local mail server anyway...if I want to send mail to user@aol.com, I'd
> be just as likely to connect to aol.com's mail server as to my own.
You really want to do MX record lookups and multiple host fallback? I'll
answer for you: No, you don't. Let the programs written to do that stuff
do their jobs.
> The advantage, to my mind, of the Net::SMTP module, is that your Perl
> script is portable to machines on which sendmail might be:
> - Non-existant
> - In a non-standard location
> - Buggy
> - Improperly configured
And isn't portable to many, many machines where sendmail *is* properly
installed and working.
> But when you connect to a mail server with Net::SMTP, that server will
> queue the messages for you.
Unless it returns a temporary failure error. Then what do you do?
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Tue, 05 May 1998 22:21:59 GMT
From: D.Haywood@btinternet.com (Dave Haywood)
Subject: Expect / DynaLoader error?
Message-Id: <6io38b$6mj$1@uranium.btinternet.com>
Hi,
I am trying to write a program to use the Expect module. Expect uses
IO:Stty and IO:Tty. Here's the error:
root> ./cpw abc abc123
Can't load '/opt/gnu/lib/perl5/sun4-solaris/5.00404/auto/IO/IO.so' for
module IO: ld.so.1: /bin/perl: fatal: relocation error: symbol not
found: main: referenced in
/opt/gnu/lib/perl5/sun4-solaris/5.00404/auto/IO/IO.so at
/opt/gnu/lib/perl5/sun4-solaris/5.00404/DynaLoader.pm line 166.
at /opt/gnu/lib/perl5/sun4-solaris/5.00404/IO/Handle.pm line 248
BEGIN failed--compilation aborted at /opt/gnu/lib/perl5/site_perl/IO/Tty.pm line 9.
BEGIN failed--compilation aborted at /opt/gnu/lib/perl5/site_perl/IO/Pty.pm line 7.
BEGIN failed--compilation aborted at /opt/gnu/lib/perl5/site_perl/Expect.pm line 14.
BEGIN failed--compilation aborted at ./cpw line 5.
I don't understand this error can anyone help and suggest what might be the
problem / where to start looking to fix it?
Here's the program:
#!/bin/perl
# use diagnostics -verbose;
use Expect;
$userid = shift @ARGV; # first arg is user id
$pwd = shift @ARGV; # second is password to set
# check we have a username and password
unless ($userid ne '' && $pwd ne '') {
print STDERR "Usage: $0 <username> <password>\n";
exit -1;
}
# start passwd
($passwd = Expect->spawn("passwd $userid")) || die "Can't spawn passwd: $!";
# look for prompts:
# New password:
# Re-enter new password:
# Time out if we don't get it within 30 seconds.
unless ($passwd->expect(30,"New password: ")) {
die "Didn't get New password prompt!\n";
}
# send the password
print $passwd "$pwd\r";
# make sure the next prompt arrives
unless ($passwd->expect(30,"Re-enter new password: ")) {
die "Didn't get password confirmation prompt!\n";
}
$passwd -> soft_close();
Thanks,
Dave Haywood
D.Haywood@btinternet.com
------------------------------
Date: 05 May 1998 15:45:47 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: How to send email (was Re: Ever Wonder Why Not Everyone Uses Modules?)
Message-Id: <m3somocp5w.fsf@windlord.Stanford.EDU>
Bennett Todd <bet@network.rahul.net> writes:
> My favourite approach is pretty simple-minded, and portable to absolutely
> anything I'll every care about porting to:-).
> use IO::File;
> $ENV{'PATH'} .= ':/usr/sbin:/usr/lib';
> my($mail) = IO::File->new('|sendmail ' . join(' ',@who)) or die;
If any of the e-mail addresses you're sending mail to contained shell
metacharacters, you've just compromised the security of your system.
> The "-t" option is available on sendmail and widely emulated by other
> MTAs; I'm not personally all that fond of it anyway.
There's a good reason to use it, however.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Tue, 05 May 1998 17:00:05 -0600
From: johnvv@earthling.net
To: gbarr@ti.com
Subject: IO::Sockets, Sample code needed
Message-Id: <6io258$ntu$1@nnrp1.dejanews.com>
I have a client/server pair running but a lot of it was trial and error cut
from various books.
I would be really grateful if someone could point me to OO sample scripts
which
are well hammered out since my code will soon turn to spaghetti if I try to
implement it in my DB application.
Thanks in advance, John van V.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 5 May 1998 22:43:50 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: IO::Sockets, Sample code needed
Message-Id: <6io4n6$sk7$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
johnvv@earthling.net writes:
:I have a client/server pair running but a lot of it was trial and error cut
:from various books.
:
:I would be really grateful if someone could point me to OO sample scripts
:which
I see you have MSFMH wrapping enabled.
:are well hammered out since my code will soon turn to spaghetti if I try to
:implement it in my DB application.
What does OO have to do with anything?
Did you read the 5.004 version of the perlipc manpage, which has a lot
of examples?
--tom
Oh, here's one for you. But YANETUT.
#!/usr/bin/perl -w
# fwdport -- act as proxy forwarder for dedicated services
use strict; # require declarations
use Getopt::Long; # for option processing
use Net::hostent; # by-name interface for host info
use IO::Socket; # for creating server and client sockets
use POSIX ":sys_wait_h"; # for reaping our dead children
my (
%Children, # hash of outstanding child processes
$REMOTE, # whom we connect to on the outside
$LOCAL, # where we listen to on the inside
$SERVICE, # our service name or port number
$proxy_server, # the socket we accept() from
$ME, # basename of this program
);
($ME = $0) =~ s,.*/,,; # retain just basename of script name
check_args(); # processing switches
start_proxy(); # launch our own server
service_clients(); # wait for incoming
die "NOT REACHED"; # you can't get here from there
# process command line switches using the extended
# version of the getopts library.
sub check_args {
GetOptions(
"remote=s" => \$REMOTE,
"local=s" => \$LOCAL,
"service=s" => \$SERVICE,
) or die <<EOUSAGE;
usage: $0 [ --remote host ] [ --local interface ] [ --service service ]
EOUSAGE
die "Need remote" unless $REMOTE;
die "Need local or service" unless $LOCAL || $SERVICE;
}
# begin our server
sub start_proxy {
my @proxy_server_config = (
Proto => 'tcp',
Reuse => 1,
Listen => SOMAXCONN,
);
push @proxy_server_config, LocalPort => $SERVICE if $SERVICE;
push @proxy_server_config, LocalAddr => $LOCAL if $LOCAL;
$proxy_server = IO::Socket::INET->new(@proxy_server_config)
|| die "can't create proxy server: $@";
print "[Proxy server on ", ($LOCAL || $SERVICE), " initialized.]\n";
}
sub service_clients {
my (
$local_client, # someone internal wanting out
$lc_info, # local client's name/port information
$remote_server, # the socket for escaping out
@rs_config, # temp array for remote socket options
$rs_info, # remote server's name/port information
$kidpid, # spawned child for each connection
);
$SIG{CHLD} = \&REAPER; # harvest the moribund
accepting();
# an accepted connection here means someone inside wants out
while ($local_client = $proxy_server->accept()) {
$lc_info = peerinfo($local_client);
set_state("servicing local $lc_info");
printf "[Connect from $lc_info]\n";
@rs_config = (
Proto => 'tcp',
PeerAddr => $REMOTE,
);
push(@rs_config, PeerPort => $SERVICE) if $SERVICE;
print "[Connecting to $REMOTE...";
set_state("connecting to $REMOTE"); # see below
$remote_server = IO::Socket::INET->new(@rs_config)
|| die "remote server: $@";
print "done]\n";
$rs_info = peerinfo($remote_server);
set_state("connected to $rs_info");
$kidpid = fork();
die "Cannot fork" unless defined $kidpid;
if ($kidpid) {
$Children{$kidpid} = time(); # remember his start time
close $remote_server; # no use to master
close $local_client; # likewise
next; # go get another client
}
# at this point, we are the forked child process dedicated
# to the incoming client. but we want a twin to make i/o
# easier.
close $proxy_server; # no use to slave
$kidpid = fork();
die "Cannot fork" unless defined $kidpid;
# now each twin sits around and ferries lines of data
# see how simple the algorithm is when you can have
# multiple threads of control?
# fork's parent; master's child
if ($kidpid) {
set_state("$rs_info --> $lc_info");
select($local_client); $| = 1;
print while <$remote_server>;
kill('TERM', $kidpid); # kill my twin cause we're done
}
# fork's child; master's grandchild
else {
set_state("$rs_info <-- $lc_info");
select($remote_server); $| = 1;
print while <$local_client>;
kill('TERM', getppid()); # kill my twin cause we're done
}
exit; # whoever's still alive bites it
} continue {
accepting();
}
}
# helper function to produce a nice string in the form HOST:PORT
sub peerinfo {
my $sock = shift;
my $hostinfo = gethostbyaddr($sock->peeraddr);
return sprintf("%s:%s",
$hostinfo->name || $sock->peerhost,
$sock->peerport);
}
# reset our $0, which on some systems make "ps" report
# something interesting: the string we set $0 to!
sub set_state { $0 = "$ME [@_]" }
# helper function to call set_state
sub accepting {
set_state("accepting proxy for " . ($REMOTE || $SERVICE));
}
# somebody just died. keep harvesting the dead until
# we run out of them. check how long they ran.
sub REAPER {
my $child;
my $start;
while (($child = waitpid(-1,WNOHANG)) > 0) {
if ($start = $Children{$child}) {
my $runtime = time() - $start;
printf "Child $child ran %dm%ss\n",
$runtime / 60, $runtime % 60;
delete $Children{$child};
} else {
print "Bizarre kid $child exited $?\n";
}
}
# If I had to choose between System V and 4.2, I'd resign. --Peter Honeyman
$SIG{CHLD} = \&REAPER;
};
--
Tom Christiansen tchrist@jhereg.perl.com
In general, if you think something isn't in Perl, try it out, because it
usually is. :-)
--Larry Wall in <1991Jul31.174523.9447@netlabs.com>
------------------------------
Date: 5 May 1998 21:54:44 GMT
From: capned@itchy.serv.net (Keith Woodman)
Subject: IS THIS POSSIBE IN PERL!
Message-Id: <6io1r4$10e$1@dns2.serv.net>
My company needs to have a program that will go out and check to see if the links we have on
pages around the world are still active on those pages.
We don't want to have to do it manualy for obvious time reasons.
If this is possilbe to write such a program please mail me at the following address
keith@lightningeb.com
Thank you
Keith
------------------------------
Date: Tue, 05 May 1998 18:23:10 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: IS THIS POSSIBE IN PERL!
Message-Id: <comdog-ya02408000R0505981823100001@news.panix.com>
Keywords: from just another new york perl hacker
In article <6io1r4$10e$1@dns2.serv.net>, capned@itchy.serv.net (Keith Woodman) posted:
>My company needs to have a program that will go out and check to see if the links we have on
>pages around the world are still active on those pages.
>We don't want to have to do it manualy for obvious time reasons.
>If this is possilbe to write such a program please mail me at the following address
certainly possible. even in Perl.
--
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 <URL:http://www.pm.org>
------------------------------
Date: Tue, 05 May 1998 22:26:14 GMT
From: hawk@algonet.se (Hakan Hjelmstrom)
Subject: Re: Newbie Q: access file handles in a subroutine?
Message-Id: <35509133.28617990@news.algonet.se>
On Tue, 5 May 1998 22:13:34 +0100, "Jeremy Goldberg" wrote:
> How do you get something like the code below to work? I'm trying to make a
> wrapper for the open() function that makes a few attempts before giving up
> (in case the file in question is being written to etc.).
This is possible, take a look at the perlref manpage. If your concern
is multiple processes accessing the same file, you should take a look
at the 'flock' function.
#!/usr/bin/perl -w
use strict;
sub open_it_up {
my ($handle, $filename) = @_;
open( $handle, $filename );
}
sub close_it_down {
my ($handle) = shift;
close( $handle );
}
open_it_up ( \*FILE, "testfile" )
|| die( "No way I can open your file, sorry:\n$!" );
while ( <FILE> ) { print $_ }
close_it_down( \*FILE ) || die( "I failed to close your file:\n$!" );
Hekan Hjelmstrvm
hawk@algonet.se
------------------------------
Date: Tue, 05 May 1998 18:30:05 -0400
From: David Boyce <David.Boyce@fmr.com>
Subject: Re: Using executable pathname to define include path
Message-Id: <354F92ED.6A4C0EFF@fmr.com>
Andy Glew wrote:
>
> > > Please respond by email; I don't read this group.
> >
> > Tom Phoenix has addressed this well.
>
> Yeah, right.
>
> David: your post was of absolutely no use to me,
> since I do not read this newsgroup.
Come to think of it, answering your question was of absolutely no use to
me either. Hmmm.
> I went and learned about FindBin the hard way.
The sound you don't hear is my heart bleeding. Of course, if you were
paying attention you would know that you were supposed to try "the hard
way", presuming that means reading the documentation, first. Which is
how I found FindBin, FWIW. In any event, you get what you pay for around
here.
-David
------------------------------
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 2509
**************************************