[8393] in Perl-Users-Digest
Perl-Users Digest, Issue: 2010 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 3 12:17:22 1998
Date: Tue, 3 Mar 98 09:01:36 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 3 Mar 1998 Volume: 8 Number: 2010
Today's topics:
recursion counter bug <tballard@poci.amis.com>
Retreiving Input from MULTIPLE select (Burt Lewis)
Re: Retreiving Input from MULTIPLE select (Nathan V. Patwardhan)
Re: rounding off numbers (I R A Aggie)
rsh a continuous unix command remotely (Farid Hamjavar)
Suspected recursion counter bug <tballard@poci.amis.com>
Re: The -w switch (was Re: better way to do this?) <upsetter@shore.net>
Trying to install perl but it's core dumping - help <tan@jettech.dircon.co.uk>
Re: Web Clients book <webmaster@fccjmail.fccj.cc.fl.us>
Re: webserver configuration/cgi.pm/nt <webmaster@fccjmail.fccj.cc.fl.us>
Re: Why doesn't "tr/\x0D//d" work? (Andrew M. Langmead)
Re: Why doesn't "tr/\x0D//d" work? (Andrew M. Langmead)
Re: Why doesn't "tr/\x0D//d" work? <tchrist@mox.perl.com>
Re: Why PERL? [Re: Beginner in trouble] (I R A Aggie)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 03 Mar 1998 09:41:50 -0700
From: Thomas Ballard <tballard@poci.amis.com>
Subject: recursion counter bug
Message-Id: <34FC32CE.C61E3428@poci.amis.com>
The following will only loop 100 times in debug mode because the
recursion counter gets confused by the eval.
#!/usr/bin/perl -d
sub crash
{
die('Ack! Ya got me, pal. Flop.');
}
# main
{
my $loops = 1000;
while ($loops--)
{
eval { crash() };
print("$loops. $@") if $@;
}
}
Tom Ballard
------------------------------
Date: 3 Mar 1998 15:20:50 GMT
From: burt@ici.net (Burt Lewis)
Subject: Retreiving Input from MULTIPLE select
Message-Id: <6dh74i$7bg$1@bashir.ici.net>
Hi,
I'm using the MULTIPLE option in my form select statement and can't figure
out how I capture all the items that were selected.
My feable attempts:
open(FILE2,$infile) or die "Can't open $file2: $!\n";
print "Content-type: text/html\n\n";
while (<FILE2>) ##start at line 1 in data.txt
{
foreach $key (keys (%FORM)) ##look at each check box checked
@list=keys(%FORM);
#foreach $key (keys (%FORM))
{
#print "$key is $FORM{$key}";
print "$list";
@fields = split /\t/; ##seperate fields
$test = "$fields[1]";
#print "$test";
print "|$key|";
if ($test == $form{Comm})
{
print "<b>You have selected:$test<br>";
}
#}
#if ($line eq= "")
#{
print FILE3 "$line"; #almost works here
}
}
close FILE2;
close FILE3;
#system "rename($outfile,$infile)";
}
Appreciate any help on this.
Burt Lewis
------------------------------
Date: 3 Mar 1998 16:00:18 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Retreiving Input from MULTIPLE select
Message-Id: <6dh9ei$cs1@fridge.shore.net>
Burt Lewis (burt@ici.net) wrote:
: I'm using the MULTIPLE option in my form select statement and can't figure
: out how I capture all the items that were selected.
Use CGI.pm. You're reinventing the wheel or so it seems.
--
Nathan V. Patwardhan
------------------------------
Date: Tue, 03 Mar 1998 10:51:00 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: rounding off numbers
Message-Id: <fl_aggie-0303981051000001@aggie.coaps.fsu.edu>
In article <MPG.f66385b7b63bd61989689@news.surfnet.nl>, real@earthling.net
wrote:
+ int($number * 100 + 0.5) / 100
Which won't do the Right Thing if the value of $number is less than
zero.
printf, sprintf are the proper answers.
James
--
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>
------------------------------
Date: 3 Mar 1998 09:19:50 -0700
From: hamjavar@unm.edu (Farid Hamjavar)
Subject: rsh a continuous unix command remotely
Message-Id: <6dhaj6$1fji@pegasus.unm.edu>
greetings,
I have already implemented what I describe below
in ksh (few lines) and is working fine, but I
like to implement it in perl if I can.
Task:
There are unix commands that continuously generate out put.
Let's consider "netstat 2" which outputs every 2 seconds.
How is it done in perl to do the following pseudo code:
rsh remotehost netstat 2 >> somefile
in background.
I am trying to avoide things like this:
% rsh aix netstat 2 >> /scratch/junkfile &
[1] 36198
%
[1] + Suspended (tty input)rsh aix netstat 2 >> /scratch/junkfile
Thanks,
Farid
------------------------------
Date: Tue, 03 Mar 1998 08:54:47 -0700
From: Thomas Ballard <tballard@poci.amis.com>
Subject: Suspected recursion counter bug
Message-Id: <34FC27C7.239D4805@poci.amis.com>
I have written a looping function which does a block eval and catches
and logs exceptions. It will only log 48 exceptions before failing with
an error telling me that I am recursing 100 functions deep. Stepping
through the loop with the debugger never reveals a stack more than about
3 functions deep. It appears that somehow the recursion counter is
getting fooled to the tune of 2 functions each time the exception is
thrown. A simpler piece of code with a similar structure doesn't
exhibit the same problem, however. Sound familiar to anyone?
Thanks, Tom Ballard
------------------------------
Date: 3 Mar 1998 16:12:32 GMT
From: Art Cohen <upsetter@shore.net>
Subject: Re: The -w switch (was Re: better way to do this?)
Message-Id: <6dha5g$c9v@fridge.shore.net>
I R A Aggie <fl_aggie@thepentagon.com> wrote:
: In article <6df2f4$74e@fridge.shore.net>, Art Cohen <upsetter@shore.net> wrote:
: + Everybody in this newsgroup posts as if you're a total and complete moron
: + if you don't use the -w switch on every single perl script.
: It has a tendency to save you from "D0H!"'s...
Perhaps, I find it amusing that even though there's supposed to be "more
than one way to do it", a lot of people on this group act as if I'm an
idiot, an infidel, or a closet Friend of Bill Gates if I don't use -w and
"use strict" in every single Perl script I write. Most of the scripts I
write are less than 200 hundred lines or so, and I save a lot more time in
the long run by *not* doing everything "strictly" than I've ever lost due
to typographical errors. (I've been writing perl professionally for
almost two years).
: + Well, guess what? One of the things I (and I suspect, a lot of other
: + people) like about Perl is that I don't have to pre-declare variables!
: + They spring into existence, pre-initialized to a null variable, whenever I
: + need them.
: Yep.
: + However, if I turn the -w switch on, I get warnings about them!
: Why? If it is the warning that I think it is, once you use the variable a
: second time, the warning goes away. If you simply declare them with a my ();
: statement, the warning goes away. If you need a $junk variable, you can
: simply undef the variable, and the warning goes away.
True, but I'm just too lazy. And in scripts the the relatively small
scripts I usually write, I've never had a problem. If I ever write a large
project with many thousands of lines of perl code, I'll probably use them.
To imply that anyone who doesn't use them in every single perl script is
an idiot is ridiculous.
: + I find
: + this very annoying and not particularly helpful. If I need to initialize a
: + variable, I do it. If I don't need to, I just use the variable name, and
: + Perl works the way it was designed.
: And -w switch will also save you from making typing errors by warning you
: that a variable is being used only once. In fact, the warning message
: wonders aloud if that is indeed the case.
Yeah, but sometimes, for example, I just want to copy a piece of code from
another program -- to populate a time array, for example, I just grab the
text that says ($sec, $min, $hour .. whatever) = localtime(time) and
continue working, even though I'm not using every element in that array.
If I'm doing this in a CGI script, I'll get a warning that keeps the
script from working, but nine times out of ten, I just don't see the
benefit in defining the whole array ahead of time simply to avoid a
spurious warning that I don't really need (I know that I'm not using
$isdst -- I don't need perl to tell me). The quickest thing to do is to
write the script without using -w. Just like, if all I need to do in a
cgi script is read the input variables, I find it easiest to use
cgi-lib.pl instead of CGI.pm.
: + Does that make me an idiot or a masochist?
: Only if you like chasing your tail trying to find a subtle, but preventable
: typing goof.
Well, that rarely happens to me. Maybe it's because I'm a good typist.
Maybe it's because I try to use longer, easy to remember variable names.
I'm less likely to screw up typing a variable name like "$header_template"
than "$tmplt2" or some such. And if I do screw it up, it will be easy to
spot.
Now, I'm not arguing that the -w switch or "use strict" are bad things.
But I just find it bizarre and slightly unsettling the number of people --
supposedly knowledgeable about perl if not "gurus" -- who are eager to
jump all over anyone who dares to suggest that certain "orthodoxies"
aren't always necessary. Some people have implied that I'm a complete
moron simply because I prefer to work without them. There's supposed to be
more than one way to do it, remember? Perl is supposed to make the easy
jobs easy, remember?
Just my two cents'
--Art
National Ska/Reggae Calendar: www.ziplink.net/~upsetter/ska/calendar.html
Boston Ska Home Page: www.ziplink.net/~upsetter/ska/index.html
------------------------------
Date: Tue, 3 Mar 1998 16:14:07 -0000
From: "Tan" <tan@jettech.dircon.co.uk>
Subject: Trying to install perl but it's core dumping - help
Message-Id: <34fc2c49.0@newsread1.dircon.co.uk>
I'm trying to install the latest version of Perl (5.004) onto an HPUX box
running HP9.
However the compilation fails some way through the makefile. It seems to
fail at the "Autosplitting perl library" section.
The error I get is shown below:
sh: 238 Memory fault - core dumped
*** Error code 139
Stop.
I am using gcc compiler but since I don't have much C knowledge I don't know
where to go from here.
Any help would be gratefully appreciated.
Thanks
Tan
------------------------------
Date: Tue, 03 Mar 1998 16:08:41 GMT
From: Bill Jones <webmaster@fccjmail.fccj.cc.fl.us>
Subject: Re: Web Clients book
Message-Id: <34FC29D2.759880E4@fccjmail.fccj.cc.fl.us>
I loved that book :-)
However, here is a script which will point you in the
right direction for what you want to do :-)
#!/usr/bin/perl
#
# Web mirroring program - copy a remote website (possibly recursively) to a
# local directory.
#
# Copyright 1997 Daniel V. Klein, dan@klein.com All Rights Reserved
#
# This program may be freely copied and distributed, and used for any and
# all purposes, provided that the above copyright notice is left intact
# and unaltered, and that any modifications to this program are as freely
# distributable and copyable.
#
#
# These are the tags & attributes which are significant to webmirror.
#
my (%collect) = (
a => "href",
area => "href",
img => "src",
fig => "src",
body => "background",
form => "action",
frame => "src",
);
#
# Don't try and collect from any of these directories, on the assumption
# that they are CGI directories
#
my (%cgi_dir) = map { ($_, 1) } qw(cgi-bin htbin cgi usr-cgi bin);
my $tmpfile = "mirror-$$.tmp";
sub help {
print <<"==END==";
webmirror [-switches] URL
-allow-cgi Allow traversing of what we guess are CGI dirs
-auth acct:passwd Specify basic authorization
-help
-index_html filename Use this name instead of index.html when a
directory (not a specific file) is fetched.
-no-get Ignore URLs with a '?' in the path
-recurse Recursively descend the file tree
-start-local Use the local version of the file to start
(useful when you want to mirror a site
starting at a page, but you want to edit the
page locally first to eliminate some links)
-talkative Be very verbose
-verbose Be slightly verbose
-wait seconds Wait N seconds between requests (defaults to
0 seconds - hammer the remote server, 'cuz it
should be able to take it).
Unique abbreviations are allowed for switches. URL is usually http://...
but can use any protocol or port.
==END==
exit;
}
require 5.001;
use Time::Local;
use Getopt::Long;
use FileHandle;
use URI::URL;
use HTML::LinkExtor;
use HTTP::Request;
use HTTP::Response;
use LWP::UserAgent;
STDOUT->autoflush(1);
$Getopt::Long::autoabbrev = 1;
GetOptions(
"allow-cgi" => \$allow_cgi,
"auth=s" => \$auth,
"help" => \$help,
"index_html=s" => \$index_html,
"no-get" => \$no_GET,
"recurse" => \$recurse,
"start-local" => \$start_local,
"talkative" => \$talkative,
"verbose" => \$verbose,
"wait=i" => \$wait,
);
help() if $Getopt::Long::error || $help || @ARGV != 1;;
$verbose ||= $talkative;
$index_html ||= "index.html";
delete $collect{a} && delete $collect{area} unless $recurse;
#
# Routine used as callback to pull out the specified attribute from a tag
#
sub extract {
my ($tag, %attr) = @_;
return unless $attr{$collect{$tag}};
push (@xref, $attr{$collect{$tag}});
print "Found <$tag $collect{$tag}=$attr{$collect{$tag}}>\n" if $talkative;
}
$ua = new LWP::UserAgent;
$ua->agent("WebMirror/1.0");
#
# Set up the request, possibly with authorization acct/passwd
#
$url = new URI::URL shift;
$req = new HTTP::Request(GET => $url);
$req->authorization_basic(split /:/, $auth) if $auth;
#
# Make the parser/extractor
#
$extrator = new HTML::LinkExtor (\&extract);
#
# Request document and parse it as it arrives. Stick the incoming file in
# the appropriate place when it arrives.
#
@xref = %done = ();
print "Starting at ", $url->as_string, " " if $verbose;
$response = $ua->request($req, $tmpfile);
$url = new URI::URL $response->request->url->as_string;
$url->path($url->path . $index_html) if substr ($url->as_string, -1) eq "/";
$done{$url->as_string}++; # And save it as done
#
# Find the root of the tree above which we will not look (we use the
# URL in the response, because there might have been redirections).
#
@path = $url->path_components;
$path[-1] = "";
$root = new URI::URL $url->as_string;
$root->path(join "/", @path);
#
# Either put the just-read HTML into a file, or use the local copy to start
#
($file = $url) =~ s#.*/##;
if ($start_local) {
unlink $tmpfile;
die "No local copy of $file to start with\n" unless -e $file;
}
else {
rename ($tmpfile, $file) or
die "Cannot rename '$tmpfile' to '$file': $!\n";
print $response->code, " ", $response->message, "\n" if $verbose;
}
$extrator->parse_file ($file);
#
# Expand all image URLs to absolute ones
#
$base = $response->base;
@xref = grep {/^$root/o} map { $_ = url($_, $base)->abs; } @xref;
do_mirror (@xref);
sub do_mirror {
my (@list) = @_;
my ($url, $request);
local(@xref); # Needs to be up-level addressable by &extract
FILE: for (@list) {
next FILE if /\?/ && $no_GET; # No GET scripts
s/#.*$//; # Eliminate in-page tag referents
next FILE if $done{$_}++; # No dups
next FILE if /\.cgi$/; # No CGI
$url = new URI::URL $_;
($file = $url->as_string) =~ s/$root//o;
next FILE unless $file; # Gotta have a file name...
$file .= $index_html if substr ($file, -1) eq "/";
undef $path;
while ($file =~ m#(.*?)/#g) {
next FILE if $cgi_dir{$1};
$path .= $1;
unless (-d $path) {
print "mkdir $path\n" if $verbose;
mkdir ($path, 0755) || die "Cannot mkdir $path\n";
}
$path .= "/";
}
#
# Request document and parse it as it arrives
#
print $url->as_string, " " if $verbose;
$request = new HTTP::Request(GET => $url);
$request->authorization_basic(split /:/, $auth) if $auth;
$request->url($url);
if (-e $file) {
my ($mtime) = (stat($file))[9];
if ($mtime) {
$request->header ('If-Modified-Since' =>
HTTP::Date::time2str($mtime));
}
}
$response = $ua->request($request, $tmpfile);
if ($response->is_success) {
my $file_length = (stat($tmpfile))[7];
my ($content_length) = $response->header('Content-length');
if (defined $content_length and $file_length < $content_length) {
warn "Transfer truncated: " .
"only $file_length out of $content_length bytes received\n";
}
elsif (defined $content_length and $file_length > $content_length) {
warn "Content-length mismatch: " .
"expected $content_length bytes, got $file_length\n";
}
$target = new URI::URL $response->request->url->as_string;
if (substr ($target->as_string, -1) eq "/") {
mkdir ($file, 0755); # Errors will sort out later...
$file = $tmpfile; # For parse_file, below
}
else {
rename ($tmpfile, $file) or
die "Cannot rename '$tmpfile' to '$file': $!\n";
}
}
else {
unlink ($tmpfile);
}
print $response->code, " ", $response->message, "\n" if $verbose;
#
# Hunt down any recursive links (if asked to)
#
@xref = ();
$extrator->parse_file ($file)
if $recurse && !$response->is_error &&
$response->header('Content-type') eq "text/html";
#
# Expand all image URLs to absolute ones
#
$base = $response->base;
@xref = grep {/^$root/o} map { $_ = url($_, $base)->abs; } @xref;
do_mirror (@xref);
}
}
HTH,
Bill
Jen Lyons wrote:
> Has anyone in this NG read the O'Reilly "Programming Web Clients with
> Perl" book? (That may not be the exact title, but you know what I mean...
> I think.)
> I maintain a lot of web pages, and I'm looking for ways to "automate"
> them a bit as far as checking links, indexing, etc etc.
------------------------------
Date: Tue, 03 Mar 1998 15:57:11 GMT
From: Bill Jones <webmaster@fccjmail.fccj.cc.fl.us>
Subject: Re: webserver configuration/cgi.pm/nt
Message-Id: <34FC2723.57FDBC81@fccjmail.fccj.cc.fl.us>
See! I told you I was wrong before :-)
Anyways, sometimes you just have to rewrite code...
Sorry :-(
anne_lee@mailexcite.com wrote:
> NT SP 3 did not solve the problem
> The script was written for cgi-lib.pl under unix, I am porting it to NT by
> trying to do as little change as possible and narrow down the problem by doing
> simple task.
>
> In article <34F78276.1226EB25@fccjmail.fccj.cc.fl.us>,
> bill@astro.fccj.cc.fl.us wrote:
> >
> > Service Pack 3 is available and highly recommended.
> > Why are you mimicing cgi-lib functionality?
> >
> > CGI.pm allows html output, headers and all.
> >
> > I say the problem is - service Pack 3 required...
> > (I've been wrong before :-)
> >
> > HTH,
> > Bill
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Tue, 3 Mar 1998 15:23:01 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Why doesn't "tr/\x0D//d" work?
Message-Id: <Ep91EE.466@world.std.com>
bart.mediamind@tornado.be (Bart Lateur) writes:
>I just wish Perl would allow masking out specific kinds of warnings via
>a mask, instead of just "all or nothing".
This is being worked on for future versions of perl.
--
Andrew Langmead
------------------------------
Date: Tue, 3 Mar 1998 15:25:16 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Why doesn't "tr/\x0D//d" work?
Message-Id: <Ep91I4.65F@world.std.com>
bart.mediamind@tornado.be (Bart Lateur) writes:
>Tom Christiansen <tchrist@mox.perl.com> wrote:
>>Funny how people forget that text files are newline *terminated*.
>That's not my definition. This is:
> A text file is a file you can create using a text editor by simply
>typing.
But if I recall correctly, Tom's definition of a "text editor" is
vi. And vi makes it difficult to create a file that doesn't contain
newline terminated lines.
--
Andrew Langmead
------------------------------
Date: 3 Mar 1998 16:23:10 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Why doesn't "tr/\x0D//d" work?
Message-Id: <6dhape$act$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, bart.mediamind@tornado.be (Bart Lateur) writes:
:That's not my definition. This is:
: A text file is a file you can create using a text editor by simply
:typing.
You can make up any definition you want. That doesn't make it reasonable.
Using a "text editor", I can trivially create a file with nothing but four
^A characters in it by simply editing. That's not a text file.
Text files consist of variable-length, newline-terminated records
containing printable text. Those are the rules, and they're entirely
intuitive. Please don't resort to sophistry.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
You can't set a breakpoint on a subroutine that hasn't been
defined yet (yet). This is a topic for ongoing research... :-)
--Larry Wall in <1994Feb25.192042.17196@netlabs.com>
------------------------------
Date: Tue, 03 Mar 1998 10:09:47 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Why PERL? [Re: Beginner in trouble]
Message-Id: <fl_aggie-0303981009470001@aggie.coaps.fsu.edu>
In article <6dgs3l$12ha@newton.cc.rl.ac.uk>, mwe@unixfe.cc.rl.ac.uk (Mike
Ellwood) wrote:
+ "I was a freshman once too.."
+ Larry Wall
Somehow, I just can't picture that... :)
James
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>
------------------------------
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 2010
**************************************