[17788] in Perl-Users-Digest
Perl-Users Digest, Issue: 5208 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 27 18:05:40 2000
Date: Wed, 27 Dec 2000 15:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <977958311-v9-i5208@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 27 Dec 2000 Volume: 9 Number: 5208
Today's topics:
Accessing protected pages with LWP? <jkit@jpmorgan.com>
Re: Accessing protected pages with LWP? egwong@netcom.com
Re: Different handles in a variable (Martien Verbruggen)
Re: for var aliasing on values %hash <wescott@conterra.com>
Re: Help with searching flat files & CGI wendywds@my-deja.com
Re: How to delete items from an array? <bart.lateur@skynet.be>
Re: How to delete items from an array? <uri@sysarch.com>
Re: How to delete items from an array? (Abigail)
Re: Modules & OOP beyond Sriram's "Advanced Perl Progra <bcaligari@my-deja.com>
need perl written <ppdc@home.com>
Re: need perl written (Tad McClellan)
Re: need perl written (Martien Verbruggen)
Re: need perl written <joe+usenet@sunstarsys.com>
Re: Parsing (Tad McClellan)
Perl Script hang when run in background <breedend@NO.excite.SPAM.com>
Re: Perl Script hang when run in background <tony_curtis32@yahoo.com>
Re: Perl Script hang when run in background (Richard Zilavec)
Re: Perl's BigInts/BigFloats (Ilya Zakharevich)
Re: perlcc (Colin Watson)
rsh -n THANKS Tony!! <breedend@NO.excite.SPAM.com>
Re: want to fetch html files without LWP (Colin Watson)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 27 Dec 2000 15:47:06 -0500
From: John Kit <jkit@jpmorgan.com>
Subject: Accessing protected pages with LWP?
Message-Id: <3A4A554A.3D90AB78@jpmorgan.com>
Anyone know how to use LWP to access user name
password protected pages? I've been trying
to use credentials() in LWP::UserAgent. I have
no clue as to how. Documents are bad. Are
there any better docs out there?
Thanks ahead of time.
John
------------------------------
Date: Wed, 27 Dec 2000 22:12:23 GMT
From: egwong@netcom.com
Subject: Re: Accessing protected pages with LWP?
Message-Id: <bPt26.24348$bw.1689569@news.flash.net>
I have to disagree with you here. I find the LWP docs to be
excellent.
Anyhow, check out the section "Access to Protected Documents"
in the lwp cookbook -- do a "perldoc lwpcook" from your command
line or goto
http://velocity.activestate.com/docs/ActivePerl/site/lib/lwpcook.html
Honestly, I don't know of any better documentation that that.
Later, gator.
John Kit <jkit@jpmorgan.com> wrote:
> Anyone know how to use LWP to access user name
> password protected pages? I've been trying
> to use credentials() in LWP::UserAgent. I have
> no clue as to how. Documents are bad. Are
> there any better docs out there?
> Thanks ahead of time.
> John
------------------------------
Date: Thu, 28 Dec 2000 07:55:32 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Different handles in a variable
Message-Id: <slrn94klq4.2ud.mgjv@martien.heliotrope.home>
On Wed, 27 Dec 2000 17:46:15 +0100,
Simon Stiefel <SiStie@nuclear-network.de> wrote:
> On Wed, 27 Dec 2000, Simon Stiefel wrote:
>
>> Hi,
>
> Hi again,
>
>> I'm writing a perl-script which allows to choose whether to print the
>> result on the STDOUT or in a file.
>
> [...]
>
>> print $wheter_STDOUT_or_FILEXYZ "Something...";
>>
>> How can I say to Perl to interpret the variable
>> "$wheter_STDOUT_or_FILEXYZ" as a handle?
>
> I got it, it was:
>
> print { $whether } "Something...";
$ cat /tmp/foo.pl
#!/usr/local/bin/perl -wl
use strict;
my $foo;
open($foo, ">/tmp/fh.out") or die $!;
print $foo "Some text to print";
close $foo;
# And to make it go to STDOUT:
$foo = *STDOUT;
print $foo "Some text to print to stdout";
$ /tmp/foo.pl
Some text to print to stdout
$ cat /tmp/fh.out
Some text to print
$
See? No problems at all. No need for brackets or anything else.
Alternatively (and I tend to like this better):
You have print statements in your program that simply look like this:
print OUTPUT "stuff to print\n";
And at the start of your program you have one simply line saying:
if ($user_wants_msgs_on_stdout)
{
open(OUTPUT, ">-") or die "Can't dup STDOUT: $!";
}
else
{
open(OUTPUT, ">$output_file") or die "Can't open $outputfile: $!";
}
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | What's another word for Thesaurus?
NSW, Australia |
------------------------------
Date: Wed, 27 Dec 2000 21:44:43 GMT
From: Mike Wescott <wescott@conterra.com>
Subject: Re: for var aliasing on values %hash
Message-Id: <osn1dhr12c.fsf@eriadne.sc.rr.com>
Brendon Caligari <bcaligari@my-deja.com> writes:
> use strict;
> my %h = (
> 0 => ' zero',
> 1 => ' one',
> 2 => ' two',
> );
>
> foreach (values %h) { s/^\s*// }
> print ':', join(':', values %h), ":\n";
> exit 0;
> Using the ActivePerl 623 build for linux I get:
> :zero:one:two:
>
> However, using the build that ocmes with linux 6.2,
> (5.005_3) I got:
> : zero: one: two:
It's a difference between versions 5.5 and 5.6. Prior to 5.6
values() returned a *copy*, modification of which was not reflected
in the hash.
perldoc -f values
=item values HASH
Returns a list consisting of all the values of the named hash.
[...]
Note that you cannot modify the values of a hash this way, because
the returned list is just a copy.
From perldoc perldelta (5.6)
=item delete(), each(), values() and hash iteration are faster
The hash values returned by delete(), each(), values() and hashes
in a list context are the actual values in the hash, instead of
copies.
The ActiveState port is a 5.6 port and has the new behavior.
The perlfunc.pod has not (yet) been updated to reflect this.
Yeah, I know, "patches are welcome". :-)
--
Mike Wescott
wescott@conterra.com
------------------------------
Date: Wed, 27 Dec 2000 21:54:44 GMT
From: wendywds@my-deja.com
Subject: Re: Help with searching flat files & CGI
Message-Id: <92dof1$vod$1@nnrp1.deja.com>
Wendy wrote:
>>I have to get it to back up one level, then go down a different
path. If I put in a path, it expects to find it underneath cgi-bin
where the script lives. I think. <<
Jeff wrote:
> Then make sure that your relative paths are still pointing to the
proper directory. On a virtual host like tripod, relative paths are
probably better than absolute paths anyway since tripod may decide, on
a whim, to completely restructure the directory tree, thus rendering
you absolue paths moot. (BTW, what's with the double forward slash at
the front of your paths in your post? Unix boxes won't like that and
Win32 boxes will interpret that as a UNC name (Unix boxen may, too).
Only one slash is needed.)<
The double slashes were just one of my many tries at getting it to
work. I've decided to put all the .dat files that I'm going to search
in wendywds.tripod.com/photos. The filenames will match the name of
the subdirectory.
I've pretty much abandoned the attempt at plagiarism. It always worked
well enough in Java, but Perl still looks like what I get when my cat
walks over the keyboard. With the shift-lock on. Pretty hard to
modify someone else's stuff when you're not entirely sure what it
does... (Perl CD Bookshelf arrived, so I've been looking up things one
by one and am getting a better idea of what I'm looking at.)
So here I sit in my cgi-bin directory, trying to get chdir() to work
and change me to my /photos/ directory. I won't know the names of the
files, so I need to be able to get a list of them. (Or rather, I'll
know them, since I created them, but would rather not hard code them
into the script.)
#!/usr/local/bin/perl -w
use CGI;
$query = CGI::new();
$words = $query->param("searchWords");
print $query->header();
# just making sure the stuff from the form made it here
print $query->p("You want to search for $words.");
# trying to figure out where the heck I am... it returns a number
instead of text
print $query->p(system("pwd"));
# and here's where I'm trying to change to the /photos/ directory
$chdir_return_code = chdir('/../photos/');
# I've lost track of the things I've tried
here: '..', '../' 'photos' '/photos/' etc. So don't laugh at this
particular guess. I'd be happy if it would just CHANGE. I don't care
WHAT it changes to at this point.
print $query->p("chdir return code: $chdir_return_code");
# it returns zero, which ought to mean it worked, and yet...
# opening the current directory (right??)
$diditwork = opendir(DOT, ".");
if ($diditwork)
{print $query->p("opendir worked.")}
else
{print $query->p("opendir didn't work.")}
@alldirs = readdir(DOT);
print $query->p("stuff in current directory:\n @alldirs");
# this prints the contents of the cgi-bin directory. We're still where
we started!
If you want to see what it's doing at the moment, the search page that
calls this script is: http://wendywds.tripod.com/photosearch.html
I'm going to rest my eyes and take a look at it later. Thanks in
advance for your help.
Wendy
(who thinks she's going to like Perl better than Java...)
wendywds@hotmail.com
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 27 Dec 2000 20:13:07 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: How to delete items from an array?
Message-Id: <08jk4t863b47ebgv806qrc9d2neutrtr4l@4ax.com>
Uri Guttman wrote:
> >> @array = map { $i++ % 2 ? $_ : () } @array ;
>
> BL> That's a grep.
>
>at 4am, map and grep look the same.
What I ment was, that you emulated a grep() using map(). These are
equivalent:
grep { COND } LIST
map { COND ? $_ : () } LIST
yet this equivalence is not too obvious.
--
Bart.
------------------------------
Date: Wed, 27 Dec 2000 20:24:57 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: How to delete items from an array?
Message-Id: <x766k5boit.fsf@home.sysarch.com>
>>>>> "BL" == Bart Lateur <bart.lateur@skynet.be> writes:
BL> Uri Guttman wrote:
>> >> @array = map { $i++ % 2 ? $_ : () } @array ;
>>
BL> That's a grep.
>>
>> at 4am, map and grep look the same.
BL> What I ment was, that you emulated a grep() using map(). These are
BL> equivalent:
BL> grep { COND } LIST
BL> map { COND ? $_ : () } LIST
BL> yet this equivalence is not too obvious.
i realized that from your previous post. i was just saying i forgot the
equivilence at 4am. :)
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 27 Dec 2000 22:57:00 GMT
From: abigail@foad.org (Abigail)
Subject: Re: How to delete items from an array?
Message-Id: <slrn94ksts.qo2.abigail@tsathoggua.rlyeh.net>
Uri Guttman (uri@sysarch.com) wrote on MMDCLXXV September MCMXCIII in
<URL:news:x7bstyb95a.fsf@home.sysarch.com>:
.. >>>>> "A" == Abigail <abigail@foad.org> writes:
..
.. A> @array = @array [0, 2, 4, 6, 8 .. $#array];
..
.. A> Or, if there are no undefined elements:
..
.. A> delete @array [1, 3, 5, 7];
.. A> @array = grep {defined} @array;
..
.. well, since you always use map in a void context, here is a solution
.. using map in a list context:
..
.. my $i ;
.. @array = map { $i++ % 2 ? $_ : () } @array ;
..
.. you can switch the order of () and $_ to get the other elements. and it
.. works for any size array.
This is of course wrong. After replacing map by grep, you select 5
out of 10 elements. The original poster wanted 6. You lose $array [9].
Abigail
--
use lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";
------------------------------
Date: Wed, 27 Dec 2000 18:56:35 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: Modules & OOP beyond Sriram's "Advanced Perl Programming"
Message-Id: <92de0v$mho$1@nnrp1.deja.com>
A couple of helpful humans recommended that I lay my hands on Damain
Conway's "Object Oriented Perl" (Manning).
I did get down to buying it and must say that the book has exceeded my
expectations and besides living up to it's cover title I found it to
provide a very good 'fill in the blanks' to the bits and pieces of
knowledge picked up from other books.
Brendon
++++
In article <910pmq$s4h$1@nnrp1.deja.com>,
Brendon Caligari <bcaligari@my-deja.com> wrote:
>
>
> Now I've been a few months doing Perl and have moved most
> c/awk/sed/shell stuff to perl scripts, where I admit that many a
> tedious sysadmin job have been automated, leaving me ample free time
to
> procrastinate while the job still gets done.
>
> I would appreciate any kind recommendations to texts that cover
> Modules / OOP in more depth than O'Reilly's (fantastic) Advanced Perl
> Programming yet more 'readable' than the perl Docs / Programming Perl.
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 27 Dec 2000 20:16:10 GMT
From: "alan feiler" <ppdc@home.com>
Subject: need perl written
Message-Id: <e6s26.169202$hD4.43927751@news1.rdc1.mi.home.com>
to drive form for my server.
ppdc@ppdc.net
------------------------------
Date: Wed, 27 Dec 2000 13:57:41 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: need perl written
Message-Id: <slrn94ket5.ei9.tadmc@magna.metronet.com>
alan feiler <ppdc@home.com> wrote:
> Subject: need perl written
You are in luck! The p5p have already written perl!
If you need Perl written, then post in a newsgroup with "jobs"
in its name.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 28 Dec 2000 07:57:04 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: need perl written
Message-Id: <slrn94klt0.2ud.mgjv@martien.heliotrope.home>
On Wed, 27 Dec 2000 20:16:10 GMT,
alan feiler <ppdc@home.com> wrote:
Subject: need perl written
> to drive form for my server.
Then hire a Perl programmer.
And learn to repeat what you say in the subject in the body of the
message as well.
Martien
--
Martien Verbruggen |
Interactive Media Division | For heaven's sake, don't TRY to be
Commercial Dynamics Pty. Ltd. | cynical. It's perfectly easy to be
NSW, Australia | cynical.
------------------------------
Date: 27 Dec 2000 16:42:04 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: need perl written
Message-Id: <m3n1dha6dv.fsf@mumonkan.sunstarsys.com>
"alan feiler" <ppdc@home.com> writes:
> to drive form for my server.
> ppdc@ppdc.net
% telnet ppdc.net 80
Trying 192.41.51.201...
Connected to buybyweb.com (192.41.51.201).
Escape character is '^]'.
GET / HTTP/1.0
Host: www.ppdc.net
HTTP/1.1 200 OK
Date: Wed, 27 Dec 2000 20:51:15 GMT
Server: Apache/1.2.6 BSafe-SSL/1.1 FrontPage/3.0.4
Last-Modified: Mon, 29 Nov 1999 04:57:43 GMT
ETag: "1313e3-2d2-384207c7"
Content-Length: 722
Accept-Ranges: bytes
Connection: close
Content-Type: text/html
...
Fortunately, Perl has been ported to just about
every platform that's capable of running Apache.
Hence it's quite likely that perl has already
been written for your platform and installed
on your web server by your web hosting company.
Unfortunately, an oxymoron like
Server: Apache/1.2.6 BSafe-SSL/1.1 FrontPage/3.0.4
does not bode well for your chances that the perl
installation was done right, well, or even upgraded
in the last 2 years. You might want to ask your
web hosting company about their perl environment
before trolling through usenet for 31337-5kr1p70rZ.
--
Joe Schaefer
------------------------------
Date: Wed, 27 Dec 2000 12:32:49 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Parsing
Message-Id: <slrn94k9u1.ef4.tadmc@magna.metronet.com>
gls@byu.edu <gls@byu.edu> wrote:
>abigail@foad.org (Abigail) writes:
>
>[snip]
>> Or could you give a correct, understandable, regex to split on? Look
>> careful at the third line of the example.
>
>#!perl -w
>
>while (<DATA>) {
> print join "><", split( /\s{2,}/, $_ );
>}
>__DATA__
>root root 1 1 Mon 20:10
>root root 2 - Mon 20:10
>sistie Simon Stiefel *3 - Mon 20:12
sistie Simon Stiefelnamelong *3 - Mon 20:12
sistie Simon Stiefelnamelongr*3 - Mon 20:12
Oops!
>This regex works for the data given (Is that sufficient to be
>correct?),
That could go either way. _I_ would say that it is not correct,
but I'm a hard-case :-)
In general, you need a _specification_ for the data, not
just "some" examples.
OTOH, if the OP doesn't think carefully in creating the test
data, then why should the answerer take pains?
>This will only work if you are certain that there will never be more
>than single spaces inside a field and at least 2 spaces between fields
>(\s{2,}|\t+) may be even more general.
Well you have disclaimed it enough to CYA, that's good :-)
>But I agree that unpack is
>probably better for this case.
Seems to be general agreement all around.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 27 Dec 2000 21:15:04 GMT
From: WB3KUM/9 <breedend@NO.excite.SPAM.com>
Subject: Perl Script hang when run in background
Message-Id: <3A4A5CD0.F8559355@NO.excite.SPAM.com>
We have a Perl script that runs a remote shell to check for the
existence of a file on a remote system. When run in the foreground it
is fine. When run in the background (i.e. nohup, nohup with &, &, an
"atjob", or a cronjob) in hangs and never completes.
The goodies
Compaq (DEC) Alpha
Tru64 (OSF1) v4.0E
Perl v5.60
Has anyone seen this and enlighten us to correct this problem. We are
all novices at Perl at this time so please be patient.
Thanks
Dennis Breeden
Worldcom Conferencing Unix Administration
Please remove NO SPAM from e-mail address.
------------------------------
Date: 27 Dec 2000 15:40:58 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Perl Script hang when run in background
Message-Id: <87k88lczkl.fsf@limey.hpcc.uh.edu>
comp.lang.perl is a dead group, removed it.
>> On Wed, 27 Dec 2000 21:15:04 GMT,
>> WB3KUM/9 <breedend@NO.excite.SPAM.com> said:
> We have a Perl script that runs a remote shell to check for the
> existence of a file on a remote system. When run in the foreground
> it is fine. When run in the background (i.e. nohup, nohup with &,
> &, an "atjob", or a cronjob) in hangs and never completes.
This is a feature of how rsh works, perl is merely caught up in its
effects...
$ man rsh
If you are using csh(1) and put a rsh in the background without
redirecting its input away from the terminal, it will block even
if no reads are posted by the remote command. If no input is
desired you should redirect the input of rsh to /dev/null using
the -n option.
Follow-ups probably should go to somewhere like comp.unix.questions.
hth
t
--
Eih bennek, eih blavek.
------------------------------
Date: Wed, 27 Dec 2000 21:50:56 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: Re: Perl Script hang when run in background
Message-Id: <3a4b6241.443767000@news.tcn.net>
On Wed, 27 Dec 2000 21:15:04 GMT, WB3KUM/9
<breedend@NO.excite.SPAM.com> wrote:
>We have a Perl script that runs a remote shell to check for the
>existence of a file on a remote system. When run in the foreground it
>is fine. When run in the background (i.e. nohup, nohup with &, &, an
>"atjob", or a cronjob) in hangs and never completes.
This is covered in the rsh documentation.
man rsh
--
Richard Zilavec
rzilavec@tcn.net
------------------------------
Date: 27 Dec 2000 20:14:41 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl's BigInts/BigFloats
Message-Id: <92dijh$bpc$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Dan Harasty
<harasty@penvision.com>],
who wrote in article <3A4A09C2.F9F87BF6@penvision.com>:
> In the above code, $a is just a regular Perl scalar which Perl converts
> to a string or number depending on context. To get a true "BigFloat",
> you MUST do this:
>
> use Math::BigFloat;
> $a = new Math::BigFloat "3.45e+1000";
Apparently, nobody cares much about BigFloat to make
perl -MMath::BigFloat=:constant -wle '$a = (1+1e-20)**1e20; print $a'
work. To test overloading of constants, I made Math::BigInt work this way:
perl -MMath::BigInt=:constant -wle 'print 2**1000'
Ilya
------------------------------
Date: 27 Dec 2000 20:28:41 GMT
From: cjw44@flatline.org.uk (Colin Watson)
Subject: Re: perlcc
Message-Id: <92djdp$6m7$1@riva.ucam.org>
Geoff Toogood <geoff@brainstorm.net.au> wrote:
>I have been useing a debian system on an i386 box to attempt to compile a
>'hello world' script using the perlcc method. It seems to dump the C source
>to file ok (I don't know C so I can't tell) but when it attempts to compile
>that it dies with a missing library called '-lgdbm' I think?
On Debian, 'apt-get install libgdbmg1-dev'.
By the way, http://packages.debian.org/ is a handy way to search for
this kind of thing: searching for 'gdbm' as part of a filename gives a
reasonable hint. The '-l' bit is a flag to the C compiler.
Debian-related followups might be best sent by mail to
debian-user@lists.debian.org.
HTH,
--
Colin Watson [cjw44@flatline.org.uk]
"And after the fire there came a still small voice ..."
------------------------------
Date: Wed, 27 Dec 2000 22:46:19 GMT
From: WB3KUM/9 <breedend@NO.excite.SPAM.com>
Subject: rsh -n THANKS Tony!!
Message-Id: <3A4A7069.567CE68D@NO.excite.SPAM.com>
That was it, many thanks Tony!!
Tony Curtis wrote:
> comp.lang.perl is a dead group, removed it.
>
> >> On Wed, 27 Dec 2000 21:15:04 GMT,
> >> WB3KUM/9 <breedend@NO.excite.SPAM.com> said:
>
> > We have a Perl script that runs a remote shell to check for the
> > existence of a file on a remote system. When run in the foreground
> > it is fine. When run in the background (i.e. nohup, nohup with &,
> > &, an "atjob", or a cronjob) in hangs and never completes.
>
> This is a feature of how rsh works, perl is merely caught up in its
> effects...
>
> $ man rsh
> If you are using csh(1) and put a rsh in the background without
> redirecting its input away from the terminal, it will block even
> if no reads are posted by the remote command. If no input is
> desired you should redirect the input of rsh to /dev/null using
> the -n option.
>
> Follow-ups probably should go to somewhere like comp.unix.questions.
>
> hth
> t
> --
> Eih bennek, eih blavek.
------------------------------
Date: 27 Dec 2000 20:11:44 GMT
From: cjw44@flatline.org.uk (Colin Watson)
Subject: Re: want to fetch html files without LWP
Message-Id: <92die0$6b9$1@riva.ucam.org>
hongdou@my-deja.com wrote:
>I wnat to fetch html file from other sites,
>but I can't use LWP in my website,
Can't you install it in some private directory, if your sysadmin won't
install it for you? If you must do it manually, read on.
>so I write a CGI to do this, the source is under here:
>---------------------------------------------------
>#!/usr/bin/perl
You mean:
#!/usr/bin/perl -w
Ideally you'd also do 'use strict;' and use lexical variables with my()
rather than package variables.
>use Socket;
>use IO::Socket;
You only need the second of these.
>$port=80;
>$remote='www.perl.com';
>$uri='http://www.perl.com/';
>socket(hpSOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
>if(!connect(hpSOCK, sockaddr_in($yport, inet_aton($remote))))
^^^^^^
I'll assume this was a typo, and you meant $port?
>{
> print "cannot connect";
> exit(1);
>}
Better, and gives you a more specific error message:
die "cannot connect: $!";
>print hpSOCK "GET ".$uri."\r\n";
If you're using double-quotes already, you might as well interpolate
rather than mess about with string concatenation, and in any case you
need two CR/LFs:
print hpSOCK "GET $uri\r\n\r\n";
Of course, \r\n isn't correct on all systems, so pedantically you should
use the literal ASCII values for CR and LF:
my $CRLF = "\015\012";
print hpSOCK "GET $uri$CRLF$CRLF";
When you use a URI in an HTTP GET request, you only use the path segment
(the server already knows that you're speaking HTTP, and the assumption
used to be that it knew what the hostname was - but see below). Thus,
set $uri to '/'.
If you're requesting documents from a virtual-hosted website, this won't
work. You need to use HTTP 1.1:
print hpSOCK "GET $uri HTTP/1.1$CRLF";
print hpSOCK "Host: $remote$CRLF$CRLF";
>print <hpSOCK>;
As a CGI script, this will be broken, as with HTTP 0.9 (which you're
using implicitly) you won't get a free Content-Type: header from the
remote server. With HTTP 0.9, you need to manufacture your own somehow.
With HTTP 1.1, you'll get a bunch of HTTP headers back from the remote
server, followed by a blank line, followed by the response body; you'll
need to grab useful things like Content-Type: and drop the rest.
Of course, if this is all that you're doing within your CGI script, is
there a good reason not to use HTTP redirects? I assume you've read the
Perl CGI Programming FAQ. And if your sysadmin won't install CGI.pm, why
not?
All this is pretty ugly, and if you can use LWP somehow instead then
please do so. It'll save a lot of reinventing the wheel.
>when set $remote to my website, $uri to the html files of my website,
>it works well, but when I want to fetch html files from other website,
>it cannot work, and show "cannot connect" to me.
Check exactly what your various socket utility functions return.
--
Colin Watson [cjw44@flatline.org.uk]
Jam wants colonies. I am a jest on clowns.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 5208
**************************************