[7025] in Perl-Users-Digest
Perl-Users Digest, Issue: 650 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 24 03:07:15 1997
Date: Tue, 24 Jun 97 00:00:37 -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, 24 Jun 1997 Volume: 8 Number: 650
Today's topics:
Date:Manip DateCalc usage (Clay Irving)
Re: Debugging tutorial? (Michael Schuerig)
Re: Example in PF doesn't work <rootbeer@teleport.com>
Re: File Permissions - 'nobody' can't open file (J. Linder)
Re: Generating random numbers fast <rootbeer@teleport.com>
Re: Generating random numbers fast <rootbeer@teleport.com>
Re: Generating random numbers fast (Abigail)
Re: Help with Arrays? (Tad McClellan)
Re: Help with Arrays? (Clay Irving)
HTTPD:Authen (Daniel G. Drumm)
Re: leading zeroes <justinb@cray.com>
Re: Perl CGI passing a file <rootbeer@teleport.com>
Re: Perl from VB <rootbeer@teleport.com>
Re: PERL/CGI Database (Jay Flaherty)
Re: Random access files in PERL (Tad McClellan)
Request for Bids - Web Site Mirroring Script overby@crl.com
Re: retreive and parse an html page (J. Linder)
Re: retreive and parse an html page (Bob)
Re: stdin, stdout, exec <rootbeer@teleport.com>
Re: Testing for the non-existence of a variable. (Albert W. Dorrington)
Re: Threads in perl ? <rra@stanford.edu>
Re: uc function for PERL4 (Andrew M. Langmead)
Unsupported socket function (KaushalSha)
Re: Very Basic Perl Question on Array <rootbeer@teleport.com>
Re: what is my, lc and etc and where to learn it? (Clay Irving)
Re: When do I call srand? <rootbeer@teleport.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 22 Jun 1997 14:38:56 -0400
From: clay@panix.com (Clay Irving)
Subject: Date:Manip DateCalc usage
Message-Id: <5ojrg0$qin@panix.com>
I don't think I quite understand this subroutine. Maybe someone can shed
some light?
Take this program:
#!/usr/local/bin/perl -w
use Date::Manip;
$today = ParseDate("today");
$christmas = ParseDate("December 25th");
for $mode (0..2) {
print DateCalc($today,$christmas,$err,$mode);
print "\n";
if ($err) {
print "$err\n";
}
}
In Manip.pm:
# Location of a the global config file. Tilde (~) expansions are allowed.
$Date::Manip::GlobalCnf="";
$Date::Manip::IgnoreGlobalCnf="";
### Date::Manip variables set in the global config file
# Name of a personal config file and the path to search for it. Tilde (~)
# expansions are allowed.
$Date::Manip::PersonalCnf=".DateManip.cnf";
$Date::Manip::PersonalCnfPath=".:~";
In my program directory, I have a file .DateManip.cnf:
*HOLIDAY
1/1 = New Year's Day
third Monday in Feb = Presidents' Day
last Monday in May = Memorial Day
#7/4 = Independence Day
#1st Monday in Sep = Labor Day
second Monday in Oct = Columbus Day (observed)
second Mon in Nov = Veterans' Day (observed)
fourth Thu in Nov = Thanksgiving
12/25 = Christmas
3rd Monday in Jan = Martin Luther King Day
When I run the program, I get:
+0:0:185:9:22:54
+0:6:2:9:22:54
+0:6:2:0:0:0
When I uncomment the two holidays in my PersonalCnf file (./.DateManip.cnf),
I get:
+0:0:185:9:22:21
+0:6:2:9:22:21
+0:6:2:0:0:0
No difference (except the time) -- Why isn't is calculating business days
correctly?
--
Clay Irving See the happy moron,
clay@panix.com He doesn't give a damn,
http://www.panix.com/~clay I wish I were a moron,
My God! Perhaps I am!
------------------------------
Date: Sun, 22 Jun 1997 00:28:17 +0200
From: uzs90z@uni-bonn.de (Michael Schuerig)
Subject: Re: Debugging tutorial?
Message-Id: <1997062200281719650@rhrz-ts2-p3.rhrz.uni-bonn.de>
Petri Backstrom <petri.backstrom@icl.fi> wrote:
> Write a simple script with a couple of if-statements, a loop or two
> and a subroutine call, and run it with perl -d and try the above
> commands.
>
> There's not much more of a tutorial you need, and the rest you can
> figure out by playing with the different options.
I think what I was hoping for was somebody telling me I could forget
about that stuff as there's a nice "visual" frontend available for the
debugger... It seems there's indeed such a thing, but only for emacs.
I'm on a Mac though.
Michael
---
Michael Schuerig Airtight arguments have
mailto:uzs90z@uni-bonn.de vacuous conclusions.
http://www.uni-bonn.de/~uzs90z/ -Amelie O. Rorty
------------------------------
Date: Sun, 22 Jun 1997 10:48:55 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Eric Hilding <eric@hilding.com>
Subject: Re: Example in PF doesn't work
Message-Id: <Pine.GSO.3.96.970622103557.23485F-100000@kelly.teleport.com>
On Sun, 22 Jun 1997, Eric Hilding wrote:
> if ($line =~ m/LOCATION:\s*(.{1,24})/)
> {
> $line =~ m/LOCATION:\s*(.{1,24})/;
That's not doing anything; you just did that in the conditional of the if.
> $address = $line;
> # $address =~ s/^\s+|\s+$//g; #temp out-of-service
> $address = $1;
Why did you assign $line to $address, modify it, and then assign $1 on top
of it? That's extra work to no purpose.
> print ">$address<\n";
> }
>
> If I un# the whitespace cleanup line, I don't get an address to print.
Well, that's because $1 is set by every successful pattern match. If you
want to keep it between matches, you need to use another variable. (And
maybe you didn't want to modify $address three times.)
I think you could do what you were trying with this simpler code. (You
might even be able to improve the regular expression, if you know more
about your data.) You don't need to strip leading whitespace, since that
wouldn't be matched by your expression.
if ($line =~ m/LOCATION:\s*(.{1,24})/) {
$address = $1;
# $address =~ s/\s*$//; # strip trailing spaces, if needed
print ">$address<\n";
}
If you can make your original expression like this, you wouldn't need to
strip whitespace at all. But this one is doing something different, so it
may not work for your data.
$line =~ /LOCATION:\s*(.+?)\s*$/i
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/
------------------------------
Date: Sun, 22 Jun 1997 13:22:58 -0500
From: jann@jann.com (J. Linder)
Subject: Re: File Permissions - 'nobody' can't open file
Message-Id: <jann-2206971322580001@usr2-dialup60.mix2.boston.mci.net>
In article <EBsInM.6yq@nonexistent.com>, abigail@fnx.com wrote:
>Mission Hills Association (mha@dunraven.com) wrote on 1383 September 1993
>in <URL: news:33A31586.23AE@dunraven.com>:
>++ Hi -
>++
>++ I'm running a CGI script that needs to open a file and append data.
>++ It works fine from the shell, but not when it's invoked from a
>++ browser.
>++
>++ I think the problem must be that 'nobody' doesn't have permission
>++ to create a file in the cgi-bin directory, or in my own (I've tried
>++ both.)
>
>Bingo! 99.9% of the cgi "problems" is failing to see this.
>
>++ Can someone let me know a good workaround?
>
>Yes. Read a faq. Or ask it in a CGI group.
>It's not a Perl question.
>
>
>Abigail
Sorry, abigail...this is a perl question...seeing as how their cgi is
written in perl.
I get tired of lazy people who, instead of answering, give a smart-alek reply.
The answer is simple. chmod the directory to 755. That will allow nobody
access...just ensure that you move the file later to a secure directory or
chmod the structure afterwards with your cgi script if the data is
sensitive.
Jann
------------------------------
Date: Mon, 23 Jun 1997 11:50:04 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Aveek Datta <MoNoLiTH+@CMU.EDU>
Subject: Re: Generating random numbers fast
Message-Id: <Pine.GSO.3.96.970623114423.9838V-100000@kelly.teleport.com>
On Mon, 23 Jun 1997, Aveek Datta wrote:
> I want to find a quick way to generate decent random numbers fast.
Perl does a pretty good job of that.
> The srand specified in the Perl book seems to call ps -auwx and gzip to
> get the random seed. Won't this be relatively slow on CGI's which get
> dozens of hits per sec?
Yes, but you don't need that for a CGI script; you only need that if you
need near crypto-level unpredictability. For ordinary use, 5.004's default
argument is sufficient. (Although you may want to do something special if
you'll really be getting dozens of hits per second, so that you can avoid
using the same seed twice in the same second.)
> I'm running on Linux systems and I know /dev/random might be useful. How
> can I use that in Perl?
It may be slow, too; I haven't checked. But just open that file, use
read() to grab four bytes, and close it. Convert those bytes to a 32-bit
integer (with unpack()) and give that number to srand, and you'll have a
pretty-durn-unpredictable seed. 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/
------------------------------
Date: Mon, 23 Jun 1997 20:12:49 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Andrew M. Langmead" <aml@world.std.com>
Subject: Re: Generating random numbers fast
Message-Id: <Pine.GSO.3.96.970623200711.15285M-100000@kelly.teleport.com>
On Mon, 23 Jun 1997, Andrew M. Langmead wrote:
> I would guess that "/dev/random" is a system wide random number
> generator with a seed determined at startup.
Actually, on Linux systems which support it, /dev/random provides a stream
of (virtually) unpredictable bytes. The system keeps track of such things
as disk-timing lag to generate it, as I understand. Since this is
influenced heavily by air turbulence around the read/write heads, it's
(effectively) impossible to predect or reproduce.
/dev/random is not suitable as an ongoing source of randomness because
(among other reasons) it is quickly depleted. It's usually better to use
it to seed a good generator.
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/
------------------------------
Date: Tue, 24 Jun 1997 02:55:12 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Generating random numbers fast
Message-Id: <EC9Es0.1L3@nonexistent.com>
Aveek Datta (MoNoLiTH+@CMU.EDU) wrote on 1392 September 1993 in
<URL: news:snfeIJS00iWS0401U0@andrew.cmu.edu>:
++ I want to find a quick way to generate decent random numbers fast.
++ The srand specified in the Perl book seems to call ps -auwx and gzip to get
++ the random seed. Won't this be relatively slow on CGI's which get dozens of
++ hits per sec?
Yes, but you don't need such a seed. What you want is a high probabily
of a different number, and you don't care much if people would be able
to recreate (or predict) what the number was (is).
srand time; is bad, because you can get many hits per second.
srand time ^ $$; is bad, but to an lesser degree, as well,
see the Camel why.
srand time ^ ($$ << 15); is probably good enough for a CGI, and
fast enough.
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=new Math::BigInt+qq;$^F$^W783$[$%9889$^F47$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W98$^F76777$=56;;$^U=$]*(q.25..($^W=@^V))=>do{print+chr$^V%$^U;$^V/=$^U}while$^V!=$^W'
------------------------------
Date: Sat, 21 Jun 1997 18:50:32 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Help with Arrays?
Message-Id: <8cpho5.2k4.ln@localhost>
Maelstrom (maelstrom@deathsdoor.com) wrote:
: Hi. I'm learning Perl and am confused by the structure of Arrays. I've
It would appear that you are learning how to program at the same time.
You are using the "Llama book" ("Learning Perl", by Randal Schwartz),
right? (if not, you should be ;-)
: checked the FAQ and still can't find the answer. At the moment I have an
: array called $FORM.
That is a simple scalar, not an array. So you're right, you are confused ;-)
: One of it's fields is called 'Comments' which contains
^^^^^^^^^^^^^^^^^^
arrays have elements (as in "array element"), they don't have 'fields'.
records have fields.
: a string. As my understanding is I should be able to access each
: character in that string by $Comment[1] $Comment[2] and so on.
You misunderstand then. You can access each array element by
$comment[0], $comment[1] and so on. The first array element will
be indexed by zero, unless you do something special to change it.
If you want to access characters individually, then you can arrange
it so that each array element is a character. In what you have described
above, you have a _string_ in each array element. So you can access
each _string_ individually.
: What I'm trying to do in the snippet of code is to print each character
: individually rather than the whole string. Can anyone see what I'm doing
: wrong here? I keep getting the error
: *The server can not locate the file specified
^^^^^^^^^^
Perl does not have a server, so I don't know what you're talking
about there...
: When I was using the commented out line everything worked fine.
: if $FORM('Comments')
^ ^
You don't want parenthesis there, you want square brackets []
No, that can't be it either, because arrays are indexed by integers,
as you said above. It appears that you are trying to use a string
index there...
: {
: # print MAIL "$FORM{'Comments'}\n\n"; <-- was using this
^^^^^^^^^^^^^^^^^
Ah hah! Now I see!
You are not talking about arrays at all!
You are talking about a hash (aka 'associative array'), which is
very different from a plain array.
: $count = '1';
: foreach $count ($Comments)
You are confused about the foreach() statement too, it would appear.
foreach() is a loop. What does it loop on?
It loops on each element of the list provided in the parenthesis.
Your statement there has provided a list of length one (one string),
so the body of the loop executes only once. But, maybe not, since
I don't see any place where the scalar $Comments is assigned a value...
: {
: print MAIL "$Comments[$count]";
: }
: }
: Any help would be much appreciated.
So, let me take a try at doing what (I think) you want (UNTESTED):
if $form{Comments} { # %form is a hash 'Comments' is the index into the hash
foreach (split '', $form{Comments}) { # split returns an array for the
# foreach to loop over. split()ing
# on an empty string will result
# in each character being an
# element of the list
print MAIL; # defaults to printing the $_ special variable, and
# foreach() defaulted to putting each list element
# into $_ also
}
}
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 21 Jun 1997 19:40:07 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: Help with Arrays?
Message-Id: <5ohoon$n1m@panix.com>
In <866856252.28185@dejanews.com> Maelstrom <maelstrom@deathsdoor.com> writes:
>Hi. I'm learning Perl and am confused by the structure of Arrays. I've
>checked the FAQ and still can't find the answer. At the moment I have an
>array called $FORM. One of it's fields is called 'Comments' which contains
>a string. As my understanding is I should be able to access each
>character in that string by $Comment[1] $Comment[2] and so on.
An array is something like:
@sammie = ("learning", "Perl", "and", "confused");
This snippet of code:
print "$sammie[0]\n";
outputs:
learning
Remember: The first element of the array is 0
The thingy you're using is a hash (a key/value pair). For example:
$Sammie{desire} = "Perl Programmer";
print "$Sammie{desire}\n";
outputs:
Perl Programmer
>What I'm trying to do in the snippet of code is to print each character
>individually rather than the whole string. Can anyone see what I'm doing
>wrong here? I keep getting the error
>*The server can not locate the file specified
>When I was using the commented out line everything worked fine.
> if $FORM('Comments')
> {
> # print MAIL "$FORM{'Comments'}\n\n"; <-- was using this
> $count = '1';
> foreach $count ($Comments)
> {
> print MAIL "$Comments[$count]";
> }
> }
So, this is saying something like:
if there is something in the value for the key 'Comments'
# print to MAIL the value
let count equal 1
foreach 1 in a variable named "Comments"
print the second element of the variable "Comments"
You know, this doesn't make any sense.
If you want to print each character, you'll have to "split" the string
into characters:
@characters = split //, $string;
HTH, but I'm not sure what you really want to do!
--
Clay Irving See the happy moron,
clay@panix.com He doesn't give a damn,
http://www.panix.com/~clay I wish I were a moron,
My God! Perhaps I am!
------------------------------
Date: 24 Jun 1997 04:43:06 GMT
From: dgd@nebula.is.rpslmc.edu (Daniel G. Drumm)
Subject: HTTPD:Authen
Message-Id: <5onj8q$bbg@nebula.is.rpslmc.edu>
I answered my own question, this program works nicely to authenticate
against a simple name:password field, using crypt(). Now, I just need one
that I can tie into RSA or PGP.
How would one encrypt the password on a web browser before it was sent
across the network, if one was retrieving $password from a CGI?
P.S. I'm not sure I need to specify ncsa, although that states that I'm
just using a name,password combo and not more fields. It may default to
this.
#!/usr/local/bin/perl
use HTTPD::Authen;
use MIME::Base64;
$username = "Camel";
$password = "Moo";
$authen = new HTTPD::Authen (DBType => 'Text',
DB => 'passwd',
Server => 'ncsa');
if($authen->check("$username", "$password")) {
$result = "in";
}
else {
$result = "bogus"; }
print $result,"\n";
--
--
Daniel G. Drumm - ddrumm@rush.edu
Rush Presbyterian St. Luke's Medical Center - Chicago, IL
Network Division - Information Services
------------------------------
Date: Sun, 22 Jun 1997 13:16:08 -0500
From: Justin Banks <justinb@cray.com>
Subject: Re: leading zeroes
Message-Id: <33AD6BE8.15FB@cray.com>
Tom Phoenix wrote:
>
> On Sun, 22 Jun 1997, Justin Banks wrote:
>
> > $four =~ s/0+(\d+)/$1/o;
>
> I don't like what that does when $four is 1000. :-)
>
> -- 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/
You are absolutely right. Guess I meant
$four =~ s/^0+(\d+)/$1/o;
--
Justin Banks
Silicon Graphics Cray Research
Eagan, Minnesota
------------------------------
Date: Sun, 22 Jun 1997 12:00:02 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Alex <alex@smilie.com>
Subject: Re: Perl CGI passing a file
Message-Id: <Pine.GSO.3.96.970622115920.23485P-100000@kelly.teleport.com>
On Sun, 22 Jun 1997, Alex wrote:
> I need to write a perl program to take 2 arguments, a file name and a
> file and save it out. I have written one that will take a name and a
> line of text and keep appending the line of text to the file, but I
> really would like to send it the whole file.
> Any ideas?
I think you should write it it Perl. If you get stuck, let us know how far
you've gotten. 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/
------------------------------
Date: Mon, 23 Jun 1997 20:28:20 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Sascha Ziemann <szi@aibon.ping.de>
Subject: Re: Perl from VB
Message-Id: <Pine.GSO.3.96.970623202414.15285Q-100000@kelly.teleport.com>
On Mon, 23 Jun 1997, Sascha Ziemann wrote:
> is it possible to call Perl from Visual Basic.
If it is possible, it should be covered in the VB documentation, shouldn't
it? I'm sure that it's about the same as calling a program in any other
language, but that's a VB question, not a Perl question.
> I would like to use the textprocessing power of Perl in a VB program
> without worrying about external called processes, data exchange and
> syncing.
Oh, that's not a problem. You don't have to worry about those things. Of
course, if you don't worry about them, your program may not work. :-)
Why not write it all in Perl in the first place? You'll probably worry
less in that case. And if you still find yourself worrying too much, you
could always see a specialist. :-)
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/
------------------------------
Date: 23 Jun 1997 13:10:19 GMT
From: fty@hickory.engr.utk.edu (Jay Flaherty)
Subject: Re: PERL/CGI Database
Message-Id: <5olsjr$ori$1@gaia.ns.utk.edu>
Darren Shilson (darren.shilson@wago.de) wrote:
: Hi,
:
: Does anyone know where I can get hold of examples of databases written
: in PERL/CGI.
:
: I want to write an Employee database, but need examples to work with.
:
: I'd be grateful for any help
for your database I would use MySQL at:
http://www.tcx.se
For your access from perl I would use the DBI/DBD modules at:
http://www.hermetica.com/technologia/DBI/
Jay
--
**********************************************
Jay Flaherty fty@utk.edu
If software was free, who would pay "THE BILL"
**********************************************
-----BEGIN PGP SIGNATURE-----
Version: 2.6.2
iQCVAwUBM2jQn1OdOzizdT/5AQHaWwP/bECLFr26GWHmszDuKUXCABW9cBuhqD9z
+JrJY+jRxF8yiV8ofkbma2vXi833RFDOz4vWZRetmjSV46MiDv5xzUatjyJnr57m
DadIYs9h0geGS6WOhJyy9dRI+YqQreQRa0QUW6NhYjdJJSrN/naYhPOfgS1mGhHX
P0RIJXP5JKI=
=edAe
-----END PGP SIGNATURE-----
------------------------------
Date: Mon, 23 Jun 1997 22:38:07 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Random access files in PERL
Message-Id: <vefno5.dm9.ln@localhost>
Don Botten (donb@wcnet.org) wrote:
: I want to read and write to Random access files. For example, I want to
: be able to change only one record of a file, or goto a particular spot
: to read some data. I have a few of Sams books on perl but cannot find
: anything on random access files.
: Can anyone point me in the right direction?
seek() in the perlfunc man page...
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Tue, 24 Jun 1997 00:21:24 -0600
From: overby@crl.com
Subject: Request for Bids - Web Site Mirroring Script
Message-Id: <867129180.1800@dejanews.com>
Hello,
The Internet Guide to Hostelling (www.hostels.com), is currently
seeking assistance to develop a script that will be used to
mirror web sites at other locations to our server.
The Request for Bids Specification for this project is located at
http://www.hostels.com/mirroring/
Interested parties with experience in Unix and/or PERL should
contact the editor as indicated in the Request for Bids.
Thank you.
Sincerely,
Darren Overby, Editor
The Internet Guide to Hostelling
www.hostels.com
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Sun, 22 Jun 1997 13:32:58 -0500
From: jann@jann.com (J. Linder)
Subject: Re: retreive and parse an html page
Message-Id: <jann-2206971332580001@usr2-dialup60.mix2.boston.mci.net>
In article <33A53F79.F861A915@irg.net>, TJ Grewal <tj@irg.net> wrote:
>I need pointers on how i can retreive a remote html page which consists
>of comma delimited text. The parsing shouldnt be a problem, but how do i
>grab the page?
>
>Any help appreciated
>
>TJ
What system are you running this on?
is Lynx installed?
If so, try the following:
(remove the leading - before using)
-One approach, if you have the lynx text-based HTML browser installed -on
your system, is this:
-
- $html_code = `lynx -source $url`;
- $text_data = `lynx -dump $url`;
-
basically, that tells the perl interpreter to shell to lynx and pull up
that page. Then it puts it in the variable $text_data.
----OR----
-The libwww-perl (LWP) modules from CPAN provide a more powerful way to
-do this. They work through proxies, and don't require lynx: -
- # print HTML from a URL
- use LWP::Simple;
- getprint "http://www.sn.no/libwww-perl/"; -
- # print ASCII from HTML from a URL
- use LWP::Simple;
- use HTML::Parse;
- use HTML::FormatText;
- my ($html, $ascii);
- $html = get("http://www.perl.com/");
- defined $html
- or die "Can't fetch HTML from http://www.perl.com/";
- $ascii = HTML::FormatText->new->format(parse_html($html)); - print $ascii;
-
hope this helps!
------------------------------
Date: Tue, 24 Jun 1997 03:53:47 GMT
From: xxbbell@voicenet.com (Bob)
Subject: Re: retreive and parse an html page
Message-Id: <5ongo1$asj$1@news2.voicenet.com>
OR,
What I do is use Net::Telnet to port 80 of the remote machine
and get the data myself.
jann@jann.com (J. Linder) wrote:
>What system are you running this on?
>is Lynx installed?
>
>If so, try the following:
>(remove the leading - before using)
>
>-One approach, if you have the lynx text-based HTML browser installed -on
>your system, is this:
>-
>- $html_code = `lynx -source $url`;
>- $text_data = `lynx -dump $url`;
>-
>
>basically, that tells the perl interpreter to shell to lynx and pull up
>that page. Then it puts it in the variable $text_data.
>
>----OR----
>
>-The libwww-perl (LWP) modules from CPAN provide a more powerful way to
>-do this. They work through proxies, and don't require lynx: -
>- # print HTML from a URL
>- use LWP::Simple;
>- getprint "http://www.sn.no/libwww-perl/"; -
>- # print ASCII from HTML from a URL
>- use LWP::Simple;
>- use HTML::Parse;
>- use HTML::FormatText;
>- my ($html, $ascii);
>- $html = get("http://www.perl.com/");
>- defined $html
>- or die "Can't fetch HTML from http://www.perl.com/";
>- $ascii = HTML::FormatText->new->format(parse_html($html)); - print $ascii;
>-
>
>hope this helps!
--
- Bob
http://www.voicenet.com/~bbell
xxbbell@voicenet.com
remove x's to reply
------------------------------
Date: Sun, 22 Jun 1997 11:06:19 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Clayton Weaver <cgweav@eskimo.com>
Subject: Re: stdin, stdout, exec
Message-Id: <Pine.GSO.3.96.970622105050.23485G-100000@kelly.teleport.com>
On Sun, 22 Jun 1997, Clayton Weaver wrote:
> If I assign <STDIN> to <STDOUT>, $| = 1;, print <STDOUT> "$data";, and
> exec, is the data available on <STDIN> of the execed process?
This is kind of like asking this question. "If I bake a measuring cup in a
microwave and keep a tray of ice cubes in the souffle, does the frosting
come from the freezer?" :-)
First off, there's no such thing as <STDOUT>. STDOUT is an output
filehandle; you can't use the line input operator on it. And you can't
assign <STDIN> to it (or STDIN, for that matter).
When you say C<print <STDOUT> "$data";> you probably mean C<print $data;>.
There's no need for the useless quotes around $data.
Now, what I _think_ you want to know is "Is there a way to make a child
process and send some data to its standard input?" And that you can do.
But maybe that wasn't what you wanted to know.
> {process original stdin and @ARGV if any up here}
>
> while ($ARGV[0] != $someval)
That's an usual way to start a loop (and I'm not sure you want a loop
here, since you exec within it). If you mean to start a loop, be sure to
do something within it which can change the conditional, or you'll have an
infinte loop.
> {
> open(STDIN, ">-");
That should open STDIN to write to standard output. Are you sure that's
what you want? It closes standard input as a side effect. And you should
always check that it succeeded, just in case.
> $test = "test";
> $| = 1;
> print STDOUT "$test";
That's those useless quotes again. And did you maybe want to use STDIN
here? Either way, it's a little strange.
> exec('someprog', 'iteration_flag', ' '); # ' ' = "don't use /bin/sh"
> }
I'm not sure what you mean by the comment. If you call exec with a list of
arguments, Perl won't use /bin/sh in any case, so that extra "space"
argument isn't needed for that.
> {rest of program}
If the exec didn't work, you didn't tell the user. And if it did work,
you'll never get to the rest of the program. (Did you mean to use an
implicit fork to open a child process in that loop?)
> Someprog inherits the file descriptors of the process execed from
> (assuming no error on the exec), so it should have the data written on
> it's own stdin.
I think you want to open a pipe to a child process and then print to that
pipe.
> (It's just to save some process creation overhead while handling data
> without having the optimizer rearrange expressions that need to be
> evaluated in sequence. Maybe there is a builtin for this?)
I don't think that Perl's optimizer will ever "rearrange expressions that
need to be evaluated in sequence". Am I misaken about that? 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/
------------------------------
Date: 20 Jun 1997 14:02:27 -0500
From: awdorrin@ictest.delcoelect.com (Albert W. Dorrington)
Subject: Re: Testing for the non-existence of a variable.
Message-Id: <5oek44$e5l@ws051eng.ictest.delcoelect.com>
In article <atspublic-2006970608080001@max02-24.qni.com>, atspublic@bigfoot.com (Andrew Starr) writes:
:> In article <33aa1583.34610604@news.inreach.com>,
:> FIGHT-SPAMjkugler@inreach.com (Joshua J. Kugler) wrote:
:>
:> > I know you can test for the existence of a variable by using:
:> >
:> > if ($var) {#code here}
:> >
:> > But how can you test to see if $var is NOT defined?
:> >
:> > I have tried
:> >
:> > if not ($var), ifnot ($var), if !($var), and some I don't even
:> > remember.
:> >
:> [snip]
:> >
:> > Right now I am using
:> >
:> > if ($var) {} else {Code here}, but I know there has to be something
:> > more elegant than that! :)
:>
<snip>
If all you want to know is whether or not the variable has been
defined you can use:
if ( not defined($var) )
{
print "VAR not defined\n";
}
else
{
print "VAR is defined\n";
}
This is not the same as saying:
if ( $var == undef )
or if ($var eq undef )
because you would be doing a numeric or string comparison in those
cases, and an 'undef' is neither.
- Al
--
Al Dorrington awdorrin@ictest.delcoelect.com
Delco Electronics - IC CIM Database & Unix Administrator
Kokomo, Indiana, USA Phone: 765.451.9655
------------------------------
Date: 22 Jun 1997 00:41:59 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Threads in perl ?
Message-Id: <m3vi37yth4.fsf@windlord.Stanford.EDU>
Budi Rahardjo <rahard@wine.ee.umanitoba.ca> writes:
> On 19 Jun 1997 03:00:07 GMT, Zenin <zenin@best.com> wrote:
>> See fork(). No, it isn't threading but it's the best available right
>> now. You can fake shared data using SysV shared memory, and even mask
>> that more using a tied perl class.
> If I can't use thread in perl, I am forced to use Java :-(
Threading is one of the major items on the development list for Perl
5.005. The current development alpha is capable of doing some limited
threading, but it's rather far from prime time right at the moment.
--
#!/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: Sat, 21 Jun 1997 13:45:26 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: uc function for PERL4
Message-Id: <EC4ovq.Lsr@world.std.com>
tadmc@flash.net (Tad McClellan) writes:
>Bruno Pagis (pagib@aur.alcatel.com) wrote:
>: I've written a uc (capitalize) function for PERL4.
>: There is more than one way to do it. Anybody wloud have a better idea ?
>tr/a-z/A-Z/; # ignores locale though...
So did perl 4.
--
Andrew Langmead
------------------------------
Date: 24 Jun 1997 03:31:40 GMT
From: kaushalsha@aol.com (KaushalSha)
Subject: Unsupported socket function
Message-Id: <19970624033101.XAA15836@ladder02.news.aol.com>
Can anyone tell me what the following error message means.
I get this error message when I execute command "perl tmp.pl" using Perl
5.003.
Unsupported socket function "getprotobyname" called at tmp.pl line 12
I get similar message when I use C language. Is there a library file
missing that was to be included? Does it come with Perl?
Thanks for your help.
-Kaushal
------------------------------
Date: Mon, 23 Jun 1997 20:59:01 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: hcchan@wellsfargo.com
Subject: Re: Very Basic Perl Question on Array
Message-Id: <Pine.GSO.3.96.970623205444.15285U-100000@kelly.teleport.com>
On Mon, 23 Jun 1997 hcchan@wellsfargo.com wrote:
> How do I write up a perl program which will create an array.
Perl will create the array for you as soon as you start using it. (Perl
lets you declare an array, but you don't need to do that for beginner's
programs.)
> I don't know how big an array I should set aside.
Then it's a good thing you're using Perl. Perl doesn't put limits on an
array's size, and it doesn't expect you to do so either.
Any good intoduction to Perl should teach you what you need. May I
recommend the venerable Llama book? It's described in perlbook(1), and
available from your local bookstore. 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/
------------------------------
Date: 23 Jun 1997 22:29:08 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: what is my, lc and etc and where to learn it?
Message-Id: <5onbdk$gds@panix.com>
In <Pine.SOL.3.95.970623215255.15875A-100000@lily> mike mah <esupu@warwick.ac.uk> writes:
> I feel so strange, you know. Although I finished reading Learning
>Perl, I never encounter my, lc and etc. Why is that so? Where can I get to
>learn complete (probably advance features) set of command (like above)?
Learning Perl is Perl 4 -- You'll have to wait for the new and improved
version. Meanwhile, Programming Perl and the documentation at
http://www.perl.com are the places you need to look...
--
Clay Irving See the happy moron,
clay@panix.com He doesn't give a damn,
http://www.panix.com/~clay I wish I were a moron,
My God! Perhaps I am!
------------------------------
Date: Sun, 22 Jun 1997 10:34:31 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Abigail <abigail@fnx.com>
Subject: Re: When do I call srand?
Message-Id: <Pine.GSO.3.96.970622102917.23485E-100000@kelly.teleport.com>
On Sun, 22 Jun 1997, Abigail wrote:
> Tom Phoenix (rootbeer@teleport.com) wrote on 1390 September 1993 in
Was that a Noneday or Whensday? :-)
> <URL: news:Pine.GSO.3.96.970621133024.24220B-100000@kelly.teleport.com>:
> ++
> ++ > and both need random numbers, should I call srand() in the require()'ed
> ++ > program, or only the outer program?
> ++
> ++ Once for each process is sufficient. In 5.004, Perl even calls srand() for
> ++ you if it sees that you haven't done so before you first use rand().
> ++
>
> This actually raises an annoying issue.
>
> Suppose you have a module X.pm, that needs the output of rand().
> But since you want to do the proper implementation abstraction,
> you don't require the user of the module to call srand(), but
> you call srand() in the initialization routine of the module.
> It would be real nice if there was a way to find out if srand()
> was already called or not.
Agreed. Although it should really be the caller's responsibility. (And, as
I wrote above, in 5.004, it's moot. Perl will take responsibility for
calling srand, if nobody else has, so that's good enough for me.)
-- 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/
------------------------------
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 650
*************************************