[11422] in Perl-Users-Digest
Perl-Users Digest, Issue: 5022 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 1 14:07:26 1999
Date: Mon, 1 Mar 99 11:00:34 -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 Mon, 1 Mar 1999 Volume: 8 Number: 5022
Today's topics:
Re: Can I do this w/ Perl? (Tad McClellan)
cgi question <baughj@rpi.edu>
Concerning the c.l.p.misc FAQ (was Re: *** FAQ: ANSWERS <jdf@pobox.com>
does perl discourage obfuscated code? (was Re: Perl eva <Russell_Schulz@locutus.ofB.ORG>
Re: does perl discourage obfuscated code? (was Re: Perl <jeromeo@atrieva.com>
Re: does perl discourage obfuscated code? (was Re: Perl <Russell_Schulz@locutus.ofB.ORG>
Re: does perl discourage obfuscated code? (was Re: Perl <rra@stanford.edu>
Re: FAQ 4.13: How can I find the Julian Day? <uri@home.sysarch.com>
FAQ 7.14: How can I pass/return a {Function, FileHandle <perlfaq-suggestions@perl.com>
FAQ 7.15: How do I create a static variable? <perlfaq-suggestions@perl.com>
FAQ 7.24: Why can't a method included in this same file <perlfaq-suggestions@perl.com>
Forcing data to be a numeric float value <cbeatson@mail.ci.lubbock.tx.us>
Re: Forcing data to be a numeric float value <jdf@pobox.com>
Re: Getting user ID and password in perl script <thewheel@stlnet.com>
Help - regex to extract two fields in "uptime" (Ken Gaugler)
Re: Help - regex to extract two fields in "uptime" <rra@stanford.edu>
Re: Help!! <jdf@pobox.com>
Help! <frothycoffee@email.msn.com>
Re: Help! <greg2@surfaid.org>
Re: How2 ! Expand Command Line Argument Wildcards? <Russell_Schulz@locutus.ofB.ORG>
HTML::TreeBuilder and $p->warn to validate HTML? (Bill Moseley)
Re: libwww-perl vs. telnet to port 80 <gisle@aas.no>
Re: localtime -> time (Abigail)
Re: Matching (newbie) (Larry Rosler)
Re: matching multiple times and remembering each match <ebohlman@netcom.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 28 Feb 1999 06:41:38 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Can I do this w/ Perl?
Message-Id: <i1abb7.0mh.ln@magna.metronet.com>
Ken (cant_take@thespam.com) wrote:
: abigail@fnx.com (Abigail) wrote:
: >Ken Loomis (kloomis@it-resourcesSPAMX.com) wrote on MMVI September
: >MCMXCIII in <URL:news:36d78f01.14244715@news.tiac.net>:
: >@@ There are two applications I'd like and I'm wondering if I can do them
: >@@ with Perl, and what the degree of difficulty of each would be (low,
: >@@ medium, or high).
: >@@
: >@@ First, I'm the administrator of a soccer league. I need to collect
: >@@ scores. Can I set up a web page where the managers can logon and
: >@@ enter their own scores.
: >
: >This is trivial when it comes to Perl. In fact, there's no need to take
: >Perl out of its wrapper if you're going to create web pages.
: >
: >@@ Second, I'd like to have users enter events on a web based calendar.
: >
: >Also trivial in Perl. Users aren't Perl driven, they run on hamburgers.
: >Again, Perl can quietly rest while you educate your users to enter events.
: >
: >
: >
: >Abigail
: A little cryptic, Abigail. Are you saying I don't need Perl to have
: users enter data on a web page?
Abigail was being quite literal about what you said.
That's right, you don't need Perl to have users enter data on a web page.
: How would I do it then?
With an HTML editor, or even a plain text editor, and an HTTP server.
However, to _do something_ with the data that those users enter,
you _do_ need some sort of CGI program to handle the returned
form values. (but you didn't ask about what to _do_ with the
entered data)
Some people choose to write such a CGI program in C or Visual
Basic or any other language.
Perl is the overwhelming choice of language for such things, but
Perl does not equal CGI.
To do what you want, you need to learn about two separate things:
Common Gateway Interface (CGI) and Perl (or some other programming
language).
Understanding which of those realms your current question falls
into will go a long way towards getting the question answered
because the folks that know the answers in the different realms
hang out in different places.
If your question is about Perl, then the question should be
posted here.
If your question is about CGI, the the question should be
posted elsewhere (comp.infosystems.www.authoring.cgi).
You can start with the Perl FAQ, part 9, which has URLs for
places to find out about the CGI side of things.
Good luck!
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 01 Mar 1999 02:47:40 -0500
From: Justin Baugh <baughj@rpi.edu>
Subject: cgi question
Message-Id: <36DA461C.6B684D22@rpi.edu>
When I run my cgi script from a shell, it works fine...when I try to
execute it from the webserver, I get this in the error logs:
[Mon Mar 1 07:40:40 1999] access to
/home/mideprov/mideprovince-www/cgi-bin/pdb failed for XXX.XXX.XXX.XXX,
reason: attempt to invoke directory as script
And I get a 403 for /cgi-bin/pdb.
The script is within the /cgi-bin/pdb directory...
What I don't understand is, the script works _FINE_ from the command
line. Outputs pretty style sheeted HTML and all that with the proper
Content-type: text/html\n\n stuff...but it refuses to work from the
browser. Any browser.
Any help would be appreciated (Or do I need to post the script?)
Thanks,
-jdb
--
************************************
Justin D. Baugh - CompSci@RPI (2001)
email baughj at rpi dot edu
"Reality is that which, when you stop believing in it,
is still there." - Philip K. Dick
"I am so hip I can't see over my pelvis." - Zaphod Beeblebrox
PGP Public Key available: http://www.rpi.edu/~baughj/pubkeys.html
------------------------------
Date: 28 Feb 1999 12:14:57 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: Andrew Fry <andrewf@beausys.demon.co.uk>
Subject: Concerning the c.l.p.misc FAQ (was Re: *** FAQ: ANSWERS TO YOUR QUESTIONS! READ FIRST! Posted Twice Weekly ***)
Message-Id: <m37lt2xxf2.fsf_-_@joshua.panix.com>
Andrew Fry <andrewf@beausys.demon.co.uk> writes:
> "This newsgroup is reserved for use by us Perl experts to discuss
> *INTERESTING* Perl issues. Dont waste our time by posting uninteresting
> questions.
That is an outrageous distortion of the twice-a-week FAQ. I can find
nothing in that document that bears on whether a question is
"interesting". It concerns, rather, whether a question has already
been answered.
I'm curious to know what your specific grievences are vis-a-vis the
content and wording of the FAQ. I'm sure the FAQ maintainer would
welcome your comments and suggestions as well.
> By the time a newbiew has done all that is suggested here, Perl will
> have gone out of fashion!
I somehow managed. So did hundreds of others.
> BTW, I realize the value and importance of a person doing a little
> research and investigation of his own, and the importance of knowing
> what documentation exists and referring to it.
Well, that puts you way ahead of the curve. Why are you averse to
sharing that enlightenment?
> The key point here is that you have no right whatsoever to tell people
> how to use this newgroup...
So we should just sit back and let people trample the public garden
because they don't know any better?
I think that it's not only a right, but a *mitzvah* (hebrew for "a
good deed" or even "a commandment") to make it clear what resources
exist, and to make it known that you're expected at least to make an
effort before asking other people for help.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Sat, 27 Feb 1999 18:34:52 -0500
From: Russell Schulz <Russell_Schulz@locutus.ofB.ORG>
Subject: does perl discourage obfuscated code? (was Re: Perl evangelism)
Message-Id: <19990227.183452.7J7.rnr.w164w_-_@locutus.ofB.ORG>
comdog@computerdog.com (brian d foy) writes:
>> http://www.microsoft.com/sitebuilder/magazine/clinick_perl.asp
>>
>> Sometimes, those shortcuts can be a little
>> counterproductive, though. Perl is famous for its ability to
>> create programs that are entirely illegible to everyone but
>> the developer who wrote them. The Perl community even has
>> obfuscation contests to see who can write the most
>> unintelligible Perl code.
>
> it's almost depressing to think that someone might actually
> beleive this. Programmers, not languages, write obfuscated code;
I believe it. Perl encourages hard-to-read code. that's just the
way it is, and if you don't apply a strong discipline when writing
Perl, you're going to be the proud owner of a ton of read-only code.
I would guess only APL has ever had a higher reliance on symbols and
gave a stronger nod towards compactness. have you ever seen someone
propose an `obfuscated Smalltalk' contest?
if this is the most damaging quote you can supply from Microsoft, then
you just aren't trying! :-)
--
Russell_Schulz@locutus.ofB.ORG Shad 86c
------------------------------
Date: Mon, 01 Mar 1999 09:53:22 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
Subject: Re: does perl discourage obfuscated code? (was Re: Perl evangelism)
Message-Id: <36DAD412.CD6F92B@atrieva.com>
Russell Schulz wrote:
>
> comdog@computerdog.com (brian d foy) writes:
> I believe it. Perl encourages hard-to-read code. that's just the
> way it is, and if you don't apply a strong discipline when writing
> Perl, you're going to be the proud owner of a ton of read-only code.
Completely disagree. Given two pieces of well written code used to
accomplish the same task, I contend that perl is *more* readable than
just about any other language you can come up with.
I have seen lots of poor code written in every language I'm familiar
with, and they all had one thing in common.
I leave it to the reader to divine what that one thing is, but I'm
guessing you already know.
--
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947
The Atrieva Service: Safe and Easy Online Backup http://www.atrieva.com
------------------------------
Date: Mon, 1 Mar 1999 00:38:11 -0500
From: Russell Schulz <Russell_Schulz@locutus.ofB.ORG>
Subject: Re: does perl discourage obfuscated code? (was Re: Perl evangelism)
Message-Id: <19990301.003811.9v7.rnr.w164w@locutus.ofB.ORG>
Russell Schulz <Russell_Schulz@locutus.ofB.ORG> writes:
> I believe it. Perl encourages hard-to-read code. that's just the
> way it is, and if you don't apply a strong discipline when writing
> Perl, you're going to be the proud owner of a ton of read-only code.
I'm sure everyone will know I meant to say `write-only', but... oops.
--
Russell_Schulz@locutus.ofB.ORG Shad 86c
------------------------------
Date: 28 Feb 1999 00:01:11 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: does perl discourage obfuscated code? (was Re: Perl evangelism)
Message-Id: <yllnhjlzy0.fsf@windlord.stanford.edu>
Russell Schulz <Russell_Schulz@locutus.ofB.ORG> writes:
> I would guess only APL has ever had a higher reliance on symbols and
> gave a stronger nod towards compactness. have you ever seen someone
> propose an `obfuscated Smalltalk' contest?
Actually, among all of the languages that I know, the one that takes the
prise for the most generally unreadable language (and it's not even
*close*) is FORTRAN, mostly due to the variable naming conventions that
most FORTRAN programmers use.
Perl honestly isn't anywhere near the same ballpark, if you're looking at
actual production Perl code.
--
#!/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: 01 Mar 1999 02:44:44 -0500
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: FAQ 4.13: How can I find the Julian Day?
Message-Id: <x7sobpfyc3.fsf@home.sysarch.com>
>>>>> "I" == ICG <postmaster@UU.NET> writes:
I> In article <MPG.113b4deb892be441989a6a@nntp.hpl.hp.com>, lr@hpl.hp.com (Larry Rosler) wrote:
>> In article <36d17cde@csnews> on 22 Feb 1999 08:50:54 -0700, Tom
>> Christiansen <tchrist@mox.perl.com> says...
>>> In comp.lang.perl.misc,
>>> smithj@statenislandonline.com writes:
>>> :Can someone please tell me how to do this without the mod.
>>>
>>> Sure -- read the source.
>>
>> Or pick up this function directly from the Perl Function Repository:
I> Why a function? If you are in a Linux environ try this:
I> # Get Julian date variable NO PARTICULAR REASON, JUST GET IT
I> $date = `/bin/date '+%y%j'`;
because a function is faster and more portable than calling a subprocess.
good enough reasons?
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: 27 Feb 1999 23:02:37 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 7.14: How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regexp}?
Message-Id: <36d8dbfd@csnews>
(This excerpt from perlfaq7 - Perl Language Issues
($Revision: 1.24 $, $Date: 1999/01/08 05:32:11 $)
part of the standard set of documentation included with every
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq7.html
if your negligent system adminstrator has been remiss in his duties.)
How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regexp}?
With the exception of regexps, you need to pass references to these
objects. See the section on "Pass by Reference" in the perlsub manpage
for this particular question, and the perlref manpage for information on
references.
Passing Variables and Functions
Regular variables and functions are quite easy: just pass in a
reference to an existing or anonymous variable or function:
func( \$some_scalar );
func( \@some_array );
func( [ 1 .. 10 ] );
func( \%some_hash );
func( { this => 10, that => 20 } );
func( \&some_func );
func( sub { $_[0] ** $_[1] } );
Passing Filehandles
To pass filehandles to subroutines, use the `*FH' or `\*FH'
notations. These are "typeglobs" - see the section on "Typeglobs and
Filehandles" in the perldata manpage and especially the section on
"Pass by Reference" in the perlsub manpage for more information.
Here's an excerpt:
If you're passing around filehandles, you could usually just use the
bare typeglob, like *STDOUT, but typeglobs references would be
better because they'll still work properly under `use strict
'refs''. For example:
splutter(\*STDOUT);
sub splutter {
my $fh = shift;
print $fh "her um well a hmmm\n";
}
$rec = get_rec(\*STDIN);
sub get_rec {
my $fh = shift;
return scalar <$fh>;
}
If you're planning on generating new filehandles, you could do this:
sub openit {
my $name = shift;
local *FH;
return open (FH, $path) ? *FH : undef;
}
$fh = openit('< /etc/motd');
print <$fh>;
Passing Regexps
To pass regexps around, you'll need to either use one of the highly
experimental regular expression modules from CPAN (Nick Ing-
Simmons's Regexp or Ilya Zakharevich's Devel::Regexp), pass around
strings and use an exception-trapping eval, or else be very, very
clever. Here's an example of how to pass in a string to be regexp
compared:
sub compare($$) {
my ($val1, $regexp) = @_;
my $retval = eval { $val =~ /$regexp/ };
die if $@;
return $retval;
}
$match = compare("old McDonald", q/d.*D/);
Make sure you never say something like this:
return eval "\$val =~ /$regexp/"; # WRONG
or someone can sneak shell escapes into the regexp due to the double
interpolation of the eval and the double-quoted string. For example:
$pattern_of_evil = 'danger ${ system("rm -rf * &") } danger';
eval "\$string =~ /$pattern_of_evil/";
Those preferring to be very, very clever might see the O'Reilly
book, *Mastering Regular Expressions*, by Jeffrey Friedl. Page 273's
Build_MatchMany_Function() is particularly interesting. A complete
citation of this book is given in the perlfaq2 manpage.
Passing Methods
To pass an object method into a subroutine, you can do this:
call_a_lot(10, $some_obj, "methname")
sub call_a_lot {
my ($count, $widget, $trick) = @_;
for (my $i = 0; $i < $count; $i++) {
$widget->$trick();
}
}
Or you can use a closure to bundle up the object and its method call
and arguments:
my $whatnot = sub { $some_obj->obfuscate(@args) };
func($whatnot);
sub func {
my $code = shift;
&$code();
}
You could also investigate the can() method in the UNIVERSAL class
(part of the standard perl distribution).
--
"C is not a big language, and it's not well served by a big book." (Brian W.
Kernighan and Dennis M. Ritchie, in "The C programming Language", Prentice
Hall 1988)
------------------------------
Date: 28 Feb 1999 01:32:41 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 7.15: How do I create a static variable?
Message-Id: <36d8ff29@csnews>
(This excerpt from perlfaq7 - Perl Language Issues
($Revision: 1.24 $, $Date: 1999/01/08 05:32:11 $)
part of the standard set of documentation included with every
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq7.html
if your negligent system adminstrator has been remiss in his duties.)
How do I create a static variable?
As with most things in Perl, TMTOWTDI. What is a "static variable" in
other languages could be either a function-private variable (visible
only within a single function, retaining its value between calls to that
function), or a file-private variable (visible only to functions within
the file it was declared in) in Perl.
Here's code to implement a function-private variable:
BEGIN {
my $counter = 42;
sub prev_counter { return --$counter }
sub next_counter { return $counter++ }
}
Now prev_counter() and next_counter() share a private variable $counter
that was initialized at compile time.
To declare a file-private variable, you'll still use a my(), putting it
at the outer scope level at the top of the file. Assume this is in file
Pax.pm:
package Pax;
my $started = scalar(localtime(time()));
sub begun { return $started }
When `use Pax' or `require Pax' loads this module, the variable will be
initialized. It won't get garbage-collected the way most variables going
out of scope do, because the begun() function cares about it, but no one
else can get it. It is not called $Pax::started because its scope is
unrelated to the package. It's scoped to the file. You could conceivably
have several packages in that same file all accessing the same private
variable, but another file with the same package couldn't get to it.
See the section on "Peristent Private Variables" in the perlsub manpage
for details.
--
When in doubt, parenthesize. At the very least it will let some
poor schmuck bounce on the % key in vi.
--Larry Wall in the perl man page
------------------------------
Date: 1 Mar 1999 00:03:12 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 7.24: Why can't a method included in this same file be found?
Message-Id: <36da3bb0@csnews>
(This excerpt from perlfaq7 - Perl Language Issues
($Revision: 1.24 $, $Date: 1999/01/08 05:32:11 $)
part of the standard set of documentation included with every
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq7.html
if your negligent system adminstrator has been remiss in his duties.)
Why can't a method included in this same file be found?
Some possible reasons: your inheritance is getting confused, you've
misspelled the method name, or the object is of the wrong type. Check
out the perltoot manpage for details on these. You may also use `print
ref($object)' to find out the class `$object' was blessed into.
Another possible reason for problems is because you've used the indirect
object syntax (eg, `find Guru "Samy"') on a class name before Perl has
seen that such a package exists. It's wisest to make sure your packages
are all defined before you start using them, which will be taken care of
if you use the `use' statement instead of `require'. If not, make sure
to use arrow notation (eg, `Guru->find("Samy")') instead. Object
notation is explained in the perlobj manpage.
Make sure to read about creating modules in the perlmod manpage and the
perils of indirect objects in the section on "WARNING" in the perlobj
manpage.
--
Ear, but earn and wear and tear
Do not rhyme with here but ere.
------------------------------
Date: Mon, 1 Mar 1999 12:06:17 -0600
From: "Chris Beatson" <cbeatson@mail.ci.lubbock.tx.us>
Subject: Forcing data to be a numeric float value
Message-Id: <7bel5n$51p$1@spider.ci.lubbock.tx.us>
I am working on a database application which in one section requires a
numerical input. In order to ensure values that are numeric, I have been
casting them as integers as denoted in the code below:
if ($results[$a] || $results[$b] || $results[$c] || $results[$d] ||
$results[$e]) {
$results[$b]=int($results[$b]); ## <-- cast to int
$results[$c]=int($results[$c]);
$results[$d]=int($results[$d]);
$results[$e]=int($results[$e]);
$total=int($results[$b]+$results[$c]+$results[$d]);
$sql2="insert into funding values
\($PID\,\'$results[$a]\'\,$results[$b]\,$results[$c]\,$results[$d]\,$results
[$e]\,$total\)\;";
if ($db->Sql($sql2)) {&error("sql_2");}
}
Is there a way to ensure that these values are floats instead of ints so I
don't have to worry about rounding. The reason I am forcing them, is because
sometimes the value may be null in which case it needs to be made 0, or
preferably 0.0.
Any suggestions would be appreciated
Chris Beatson
------------------------------
Date: 01 Mar 1999 13:52:31 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: "Chris Beatson" <cbeatson@mail.ci.lubbock.tx.us>
Subject: Re: Forcing data to be a numeric float value
Message-Id: <m3d82tjb4g.fsf@joshua.panix.com>
"Chris Beatson" <cbeatson@mail.ci.lubbock.tx.us> writes:
> if ($results[$a] || $results[$b] || $results[$c] || $results[$d] ||
> $results[$e]) {
> $results[$b]=int($results[$b]); ## <-- cast to int
[etc.]
> Is there a way to ensure that these values are floats instead of
> ints so I don't have to worry about rounding. The reason I am
> forcing them, is because sometimes the value may be null in which
> case it needs to be made 0, or preferably 0.0.
Your question is not clear. Perhaps you want something like this.
for (@results[$a,$b,$c,$d,$e]) {
$_ = sprintf "%0.1", $_ || 0;
}
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Sun, 28 Feb 1999 01:44:00 -0600
From: "T. Wheeler" <thewheel@stlnet.com>
Subject: Re: Getting user ID and password in perl script
Message-Id: <36D8F3C0.F5F211DD@stlnet.com>
REMOTE_USER is only set when someone logs into the server
using server authentication. So if someone is logging into
a CGI or JavaScript app, it will not (nor can it) be set.
The way to know for sure is if a dialog box pops up and asks
for a username/password pair.
You can probably imagine why your password would not be
sitting around as an environmental variable.
Tom
Seshu Madhavapeddy wrote:
>
> Thanx for the info. But this does not seem to work. Earlier, I
> was trying getting the environment variable 'REMOTE_USER' which
> used to return nothing. The method 'remote_user' also returns
> nothing. Here is my code:
>
> use CGI;
> $query=new CGI;
> $userid = $query->remote_user();
> print "UserID:$userid\n";
>
> Is ther anything wrong with this?
------------------------------
Date: Sun, 28 Feb 1999 17:20:25 GMT
From: kag@gaugler.com (Ken Gaugler)
Subject: Help - regex to extract two fields in "uptime"
Message-Id: <36d978b4.3030207@news.bayarea.net>
Hello,
I have a file full of lines of the output from "uptime", from which I would
like to extract just the time and the 1-minute load average. That is, for
the line:
8:00am up 23 day(s), 21:34, 7 users, load average: 0.13, 0.08, 0.09
I want to extract:
8:00am 0.13
note that the leading spaces are also removed.
Can someone tell me the regular expression that would eliminate the unwanted
characters?
Thanks,
Ken
------------------------------
Date: 28 Feb 1999 09:31:12 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Help - regex to extract two fields in "uptime"
Message-Id: <yl7lt2l9jz.fsf@windlord.stanford.edu>
Ken Gaugler <kag@gaugler.com> writes:
> I have a file full of lines of the output from "uptime", from which I
> would like to extract just the time and the 1-minute load average. That
> is, for the line:
> 8:00am up 23 day(s), 21:34, 7 users, load average: 0.13, 0.08, 0.09
> I want to extract:
> 8:00am 0.13
s/^\s*(\S+).*average: ([\d.]+).*/$1 $2/;
--
#!/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: 01 Mar 1999 01:07:00 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Help!!
Message-Id: <m31zj9yc8r.fsf@joshua.panix.com>
"Clawed Le Mew" <clm@biteme.com> writes:
> What if I wanted to maintain this long table in Oracle, rather than
> hard-coded in the program as I have?
http://www.hermetica.com/technologia/DBI/
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Mon, 1 Mar 1999 13:30:17 -0500
From: "Besser Web Design" <frothycoffee@email.msn.com>
Subject: Help!
Message-Id: <uVp5GDBZ#GA.246@upnetnews02.moswest.msn.net>
I am trying to get formmail to work on a new server, it's a pretty easy
process, I thought, until I tried it on this new server.
Previously, on a different server, my cgi-bin was at the same level as my
index.html.
Now, my cgi-bin is at the same level as my html directory (which contains
index.html)
Previously, I pointed my form to:
http://myname.server.com/cgi-bin/formmail.cgi but now my cgi-bin is located
higher in the directory chain than my index page. Is that incorrect? I
thought my IP address was mapped to my index page.
Anyway, I try sending my form to http://www.myname.com/cgi-bin/formmail.cgi
and that doesn't work, so then I tried my server path:
/home/usr###/cgi-bin/formmail.cgi.
I come up with an Internal Server error:
The server encountered an internal error or misconfiguration and was unable
to complete your request.
Please contact the server administrator and
inform them of the time the error occurred, and anything you might have done
that may have caused the error.
malformed header from script. Bad header=usr###... Recipient names must:
/home/usr###/cgi-bin/formmail.cgi
I have chmoded the files correctly, and uploaded them as ASCII. Does anyone
know what I am doing wrong or what I am supposed to do?
There are only so many variables for god sakes!!!
Thanks in advance for your response.
Lilah
Please email me at: webmaster@bessercreations.com
------------------------------
Date: Mon, 01 Mar 1999 18:37:20 +0000
From: Greg Griffiths <greg2@surfaid.org>
To: Besser Web Design <frothycoffee@email.msn.com>
Subject: Re: Help!
Message-Id: <36DADE60.BB30F48@surfaid.org>
try
/cgi-bin/script.pl
Besser Web Design wrote:
>
> I am trying to get formmail to work on a new server, it's a pretty easy
> process, I thought, until I tried it on this new server.
>
> Previously, on a different server, my cgi-bin was at the same level as my
> index.html.
>
> Now, my cgi-bin is at the same level as my html directory (which contains
> index.html)
>
> Previously, I pointed my form to:
> http://myname.server.com/cgi-bin/formmail.cgi but now my cgi-bin is located
> higher in the directory chain than my index page. Is that incorrect? I
> thought my IP address was mapped to my index page.
>
> Anyway, I try sending my form to http://www.myname.com/cgi-bin/formmail.cgi
> and that doesn't work, so then I tried my server path:
> /home/usr###/cgi-bin/formmail.cgi.
>
> I come up with an Internal Server error:
> The server encountered an internal error or misconfiguration and was unable
> to complete your request.
> Please contact the server administrator and
> inform them of the time the error occurred, and anything you might have done
> that may have caused the error.
>
> malformed header from script. Bad header=usr###... Recipient names must:
> /home/usr###/cgi-bin/formmail.cgi
>
> I have chmoded the files correctly, and uploaded them as ASCII. Does anyone
> know what I am doing wrong or what I am supposed to do?
>
> There are only so many variables for god sakes!!!
>
> Thanks in advance for your response.
>
> Lilah
> Please email me at: webmaster@bessercreations.com
------------------------------
Date: Sat, 27 Feb 1999 18:55:03 -0500
From: Russell Schulz <Russell_Schulz@locutus.ofB.ORG>
Subject: Re: How2 ! Expand Command Line Argument Wildcards?
Message-Id: <19990227.185503.9M5.rnr.w164w@locutus.ofB.ORG>
Richard Bobo <rbobo@spd.dsccc.com> writes:
> I am trying to use command line arguments that can have wild cards,
> but I don't want them expanded in @ARGV because I want to expand them
> later while accessing a remote file system. How can I get the raw or
> unexpanded command line that launched the perl script?
I have recommended a new environment variable be created in the
subprocess, perhaps ORIGINALENVIRONMENT -- then, for the rare routines
that didn't want the automatic globbing, they could `do' it themselves
without user intervention like quoting or `set noglob'.
I presume DejaNews still has the original thread on this, and why
people disagreed with it at that point, and why so many people mailed
me little scripts to rename all their *.c files to *.c.old (which was
rather confusing, since I already knew how to do that...).
--
Russell_Schulz@locutus.ofB.ORG Shad 86c
------------------------------
Date: Mon, 1 Mar 1999 00:08:06 -0800
From: moseley@best.com (Bill Moseley)
Subject: HTML::TreeBuilder and $p->warn to validate HTML?
Message-Id: <MPG.1143eabf9a4183c19896c5@206.184.139.132>
I'm wondering if HTML::TreeBuilder's $p->warn() will validate HTML.
I've got a CGI program where some pages generated include HTML
snipits entered in another setup program.
The Problem, is that if someone enters bad html it can screw up the
display of a web page (e.g. someone leaves off a </TABLE> in a included
HTML snipit). So, I really need something to validate that any HTML
entered has valid 'syntax' before accepting it in my setup program.
Is that what the $p->warn method is in HTML::Treebuilder does?
I'm unclear on its use, too. Something like this?
my $Contains_Syntax_Erorrs;
$h = new HTML::TreeBuilder;
$h->ignore_text( 1 ); # just validate
$h->warn( 1 ) # Call warn() on syntax errors
$SIG{__WARN__} = sub { $Contains_Syntax_Errors++ };
$h->parse( $HTML_Snipit );
die 'Bad HTML in Snipit found' if $Contains_Syntax_Errors;
--
Bill Moseley mailto:moseley@best.com
------------------------------
Date: 28 Feb 1999 01:01:33 +0100
From: Gisle Aas <gisle@aas.no>
Subject: Re: libwww-perl vs. telnet to port 80
Message-Id: <m3g17rv1k2.fsf@eik.g.aas.no>
opus@magibox.net (Carl Brock Sides) writes:
> I don't get the Client-Date, Client-Peer, or Title headers. Why not? How can the
> server "know", apart from what headers are passed to it, whether it's a human
> typing into a terminal or a libwww-perl script? Is there some magic information
> being passed by the script that I don't know about?
The Client-Xxx headers are added by LWP (the client). If you connect
to an https site you would see many more of these. The Title header
was added by the HTML::HeadParser that LWP normally invokes. Read the
HTML::HeadParser manpage to learn about other headers that it might
add. The main reason for invoking HTML::HeadParser is to get the
correct BASE URI set up ($response->base).
--
Gisle Aas
------------------------------
Date: 1 Mar 1999 18:13:36 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: localtime -> time
Message-Id: <7belcg$ajs$2@client2.news.psi.net>
johan.levin@mbox300.swipnet.se (johan.levin@mbox300.swipnet.se) wrote on
MMVII September MCMXCIII in <URL:news:7bbod5$iui$1@nnrp1.dejanews.com>:
@@ Hi!
@@
@@ I'm making a perl script that parses my syslog-file.
@@ There are times that I want to convert to "seconds-since-1970".
@@
Time::Local
Abigail
------------------------------
Date: Sat, 27 Feb 1999 23:11:50 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Matching (newbie)
Message-Id: <MPG.11428c06f2bf61789896aa@nntp.hpl.hp.com>
In article <36d94123.0@news1.jps.net>, on Sat, 27 Feb 1999 20:53:24 -
0800 no_amaring@jps.net says...
> I need to figure out if a string has any non alphanumeric characters in it.
> Unfortunately, the one thing I do not have a good grasp on is the type of
> pattern matching that is required. Someone want to please explain this one
> to me?
if ($string =~ /\W/) { print "Found a non-alphanumeric\n" }
I will not explain this one to you, because it is explained very clearly
in 'perlre' in your Perl documentation.
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 1 Mar 1999 08:28:53 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: matching multiple times and remembering each match
Message-Id: <ebohlmanF7wq85.50D@netcom.com>
Eric Smith <eric@fruitcom.com> wrote:
: > A more extensive surgery would replace the whole construct by this:
: >
: > @contents = /tagA(matchedstring)tagB/g;
: Now I tried your eloquent and pithy ...
: @contents = s/%SC%([\n\w\W]*?)%EC%//g;
Nope. That's not what Larry suggested. He's using the plain old match
operator, which returns a list of matches when called in list context.
You're still using the substitution operator, which always returns the
number of matches regardless of what context it's called in.
: btw the code needs to remove the tags and the matched string from the
: output and put the matched string in at the bottom
Well, in that case you *do* need to use the substitution operator, and
you might as well just use a while loop.
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 5022
**************************************