[16963] in Perl-Users-Digest
Perl-Users Digest, Issue: 4375 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 19 14:10:27 2000
Date: Tue, 19 Sep 2000 11:10:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <969387014-v9-i4375@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 19 Sep 2000 Volume: 9 Number: 4375
Today's topics:
Re: Regex Problem <lr@hpl.hp.com>
Re: Regular Expressions: Counting matches? <dfan@harmonixmusic.com>
rename Vs system mv tonyforster@zoom.co.uk
Re: rename Vs system mv (Randal L. Schwartz)
Re: rename Vs system mv (Rafael Garcia-Suarez)
Re: Send e-mail in HTML format with sendmail (Gwyn Judd)
Re: Shortest code for Fibonacci? <jcook@strobedata.com>
Re: Shortest code for Fibonacci? (Abigail)
Re: Shortest code for Fibonacci? <russ_jones@rac.ray.com>
Re: Split NS Log File <glynFOOdwr@FSCKdeleteEmeD.co.uk>
Re: Split NS Log File <yanick@babyl.sympatico.ca>
Re: Split NS Log File <glynFOOdwr@FSCKdeleteEmeD.co.uk>
Subroutines sharing a variable (was: Difference @ARGV[0 nobull@mail.com
system load analysis tools <chad.williams@bellsouth.com>
Tutorial Perl? <gamer@freegates.be>
Re: Tutorial Perl? (Steven M. O'Neill)
Variable Handling (M. Monti)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 19 Sep 2000 09:56:46 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Regex Problem
Message-Id: <MPG.14313aaa8940c4e298ad8f@nntp.hpl.hp.com>
In article <39c752a9.15281383@news.grnet.gr> on Tue, 19 Sep 2000
11:55:50 GMT, Philip Lees <pjlees@ics.forthcomingevents.gr> says...
...
> #!perl -w
>
> use strict;
>
> my @phones = ( '223344', '123456', '555555', '334433', '334466',
> '333444', 'abcdef', '121212', '1a2b3c', ' ' );
>
> foreach ( @phones ) {
> print;
> s/(\d)\1(?!\1)(\d)\2(?!\1|\2)(\d)\3/$1$1$2$2$3$3/ or print "
> Invalid!";
> print " $_\n";
> }
The regex is a good effort, though lacking the requisite end-anchors.
But using it in a substitution that replaces what it matches by itself
is inapt. Simply matching is enough:
/^(\d)\1(?!\1)(\d)\2(?!\1|\2)(\d)\3$/ or print "Invalid!";
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 19 Sep 2000 12:58:55 -0400
From: Dan Schmidt <dfan@harmonixmusic.com>
Subject: Re: Regular Expressions: Counting matches?
Message-Id: <wk3diw71yo.fsf@turangalila.harmonixmusic.com>
Tom Briles <sariq@texas.net> writes:
| Dan Schmidt wrote:
| >
| > Larry Rosler <lr@hpl.hp.com> writes:
| >
| > | In article <wk66nt9vzk.fsf@turangalila.harmonixmusic.com> on 18 Sep 2000
| > | 18:27:27 -0400, Dan Schmidt <dfan@harmonixmusic.com> says...
| > |
| > | > $num_matches = () = m/<a href=/ig;
| > |
| > | Yuk. That is the second time that gross and inefficient solution has
| > | been posted in this thread.
| >
| > Gross is in the eyes of the beholder, on the other hand. I find it
| > grosser to go through a loop incrementing a variable than to determine
| > it in a single statement. My functional tendencies showing, I guess.
|
| What makes you think that *your* solution doesn't "go through a loop"?
Nothing makes me think that. Of course it goes through an implicit
loop. If my statement was unclear, replace my use of 'loop' by
'explicit loop'.
I wasn't referring to whether a loop is going on under the covers, but
to whether the perl code is explicitly iterating through the loop.
Anyway, we are violently agreeing.
--
Dan Schmidt | http://www.dfan.org
Honest Bob CD now available! | http://www.dfan.org/honestbob/cd.html
------------------------------
Date: Tue, 19 Sep 2000 15:01:11 GMT
From: tonyforster@zoom.co.uk
Subject: rename Vs system mv
Message-Id: <8q7v39$lvb$1@nnrp1.deja.com>
All I am trying to do is move a file from one directory to another,
using the rename command.
"Cross-device link" was the value of $!. The rename hadnt worked.
Although when I use system("mv"...) in the perl script, the file gets
moved, but $! catches an "Illegal seek".
Incidentally, the command line has no problem doing a shell "mv"....
Does Perl know something I dont?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 19 Sep 2000 08:19:12 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: rename Vs system mv
Message-Id: <m1ya0owgsv.fsf@halfdome.holdit.com>
>>>>> "tonyforster" == tonyforster <tonyforster@zoom.co.uk> writes:
tonyforster> All I am trying to do is move a file from one directory
tonyforster> to another, using the rename command.
Most likely, it's more than that... from one mounted filesystem to
another.
tonyforster> "Cross-device link" was the value of $!. The rename hadnt worked.
tonyforster> Although when I use system("mv"...) in the perl script,
tonyforster> the file gets moved, but $! catches an "Illegal seek".
tonyforster> Incidentally, the command line has no problem doing a
tonyforster> shell "mv"....
When "mv" is asked to rename a file, it first performs the equivalent
of Perl's rename() operator. However, if that fails because the
request would have had the data "leap" from one filesystem to another,
then rename() returns "cross device link", and the "mv" command falls
back to calling "cp" to *copy* the data, then unlink() to remove the
original.
Perl's rename operator is but a small part of the step.
tonyforster> Does Perl know something I dont?
No, quite the other way around, now. :)
I usually use something like this:
unless (rename $old, $new) {
if ($! =~ /link/) {
if (system '/bin/mv', $old, $new) {
warn "cannot rename or mv $old to $new\n";
}
} else {
warn "cannot rename $old to $new: $!\n";
}
}
Which thankfully is encapsulated in:
use File::Copy;
move($old,$new);
{grin}
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Tue, 19 Sep 2000 15:19:47 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: rename Vs system mv
Message-Id: <slrn8sf1cp.p4t.rgarciasuarez@rafael.kazibao.net>
tonyforster@zoom.co.uk wrote in comp.lang.perl.misc:
>All I am trying to do is move a file from one directory to another,
>using the rename command.
>
>"Cross-device link" was the value of $!. The rename hadnt worked.
The answer is, as one might have expected, in the docs:
$ perldoc -f rename
[...]
Behavior of this function varies wildly depending on your system
implementation. For example, it will usually not work across file system
boundaries, even though the system I<mv> command sometimes compensates
for this.
[...]
--
Rafael Garcia-Suarez | http://rgarciasuarez.free.fr/
------------------------------
Date: Tue, 19 Sep 2000 15:05:18 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Send e-mail in HTML format with sendmail
Message-Id: <slrn8sf05c.o36.tjla@thislove.dyndns.org>
I was shocked! How could Dimitri <d@i.am>
say such a terrible thing:
>How to send e-mail in HTML format with sendmail? The html source appear in
>the e-mail I send.
This is not a Perl question, simply because your script is written in
Perl doesn't make it so, since the question would be the same no matter
what language you had written it in. That said, I think you need to add
a Content-Type header.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Religion is something left over from the infancy of our intelligence;
it will fade away as we adopt reason and science as our guidelines.
-Bertrand Russell
------------------------------
Date: Tue, 19 Sep 2000 08:23:34 -0700
From: Jim Cook <jcook@strobedata.com>
Subject: Re: Shortest code for Fibonacci?
Message-Id: <39C784F6.E31DA07B@strobedata.com>
> >> ^^ () How do you raise powers in constant time?
> >that I must be missing something. Would you please clarify your question
> >so I am less confused?
> in bounded time*. On the other hand, in general it is not possible to
> raise powers of arbitrary real numbers in constant time. Does that help?
If Abigail meant that, I guess I misunderstood. I thought the question
was put in the context of perl.
I don't think that arbitrary real numbers are in the set of supported
perl values. Certainly in my current version, they're not actually
supported.
perl -v
This is perl, v5.6.0 built for MSWin32-x86-thread
#! perl -w
use strict;
my $overflow = 2;
for (my $i = 1; $i < 20; $i++) {
$overflow = $overflow ** 2;
print "$overflow\n";
}
4
16
256
65536
4294967296
1.84467440737096e+019
3.40282366920938e+038
1.15792089237316e+077
1.34078079299426e+154
1.#INF
1.#INF
1.#INF
1.#INF
1.#INF
1.#INF
1.#INF
1.#INF
1.#INF
1.#INF
--
jcook@strobedata.com Live Honourably 4/1 - 4/3 + 4/5 - 4/7 + . . .
2000 Tuesdays: Feb/last 4/4 6/6 8/8/ 10/10 12/12 9/5 5/9 7/11 11/7 3/14
Strobe Data Inc. home page http://www.strobedata.com
My home page O- http://jcook.net
------------------------------
Date: 19 Sep 2000 16:09:59 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Shortest code for Fibonacci?
Message-Id: <slrn8sf3sh.5fq.abigail@alexandra.foad.org>
Jim Cook (jcook@strobedata.com) wrote on MMDLXXVI September MCMXCIII in
<URL:news:39C784F6.E31DA07B@strobedata.com>:
$$ > >> ^^ () How do you raise powers in constant time?
$$
$$ > >that I must be missing something. Would you please clarify your question
$$ > >so I am less confused?
$$
$$ > in bounded time*. On the other hand, in general it is not possible to
$$ > raise powers of arbitrary real numbers in constant time. Does that help?
$$
$$ If Abigail meant that, I guess I misunderstood. I thought the question
$$ was put in the context of perl.
$$
$$ I don't think that arbitrary real numbers are in the set of supported
$$ perl values. Certainly in my current version, they're not actually
$$ supported.
*shrug* If you play it that way....
*ANY* Perl program running on whatever CPU you can make out of the particles
that either have existed in this universe, or exist now, either never
terminates, or runs in O (1) time.
Happy?
(Could someone tell Knuth most of his TAoCP is garbage? Everything runs
in O (1) time)
Abigail
--
$" = "/"; split $, => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_) {print "$_ $_{$_} "}};
%{"@_"} = %_ = (Just => another => Perl => Hacker); &{%{%_}};
------------------------------
Date: Tue, 19 Sep 2000 11:30:13 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: Shortest code for Fibonacci?
Message-Id: <39C79495.34D7C6D3@rac.ray.com>
Abigail wrote:
> *shrug* If you play it that way....
>
> *ANY* Perl program running on whatever CPU you can make out of the particles
> that either have existed in this universe, or exist now, either never
> terminates, or runs in O (1) time.
>
> Happy?
>
I'm happy! This supports something that I posited many years ago: the
odds of anything happening are 50/50. Either it will happen or it
won't.
But I also learned (from a different source) that the odds of winning
the lottery are statistically the same whether I buy a ticket or not.
What a day, it ain't often that Abigail agrees with anything I say.
--
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747
Quae narravi, nullo modo negabo. - Catullus
------------------------------
Date: Tue, 19 Sep 2000 17:06:01 +0100
From: "Glyndwr" <glynFOOdwr@FSCKdeleteEmeD.co.uk>
Subject: Re: Split NS Log File
Message-Id: <BbMx5.8256$ap5.140333@news6-win.server.ntlworld.com>
<fperkins@my-deja.com> wrote in message news:8q7umv$la5$1@nnrp1.deja.com...
> I have a log file that I need to split in order to analyze the fields.
I've never posted here before, so I'm expecting someone to come along in a
few minutes and tell me this is rubbish. Still, I'll have a go :o)
> 207.179.196.120 - - [31/Jul/2000:22:05:02 -0000] "GET / HTTP/1.0" 200
> 737 "http://www.someurl.com/url.html" "Mozilla/4.06 [en] (Win98;
> I)" "INTERSE=20724114964484603"
Rather than a simple split, I would use a regexp and then get the bits from
backreferences. Say the string is in $foo.
$foo =~ /([\d\.]{15})[\s\-]*?\[(.*?)\]\s*"(.*?)".*"(.*)"\s*"(.*)"\s"(.*)"/;
($ip,$date,$request,$url,$browser,$foo) = ($1,$2,$3,$4,$5,$6);
I haven't compiled this to test the regexp, so it might have some bloopers,
but you get the idea.
Actually, if any seasoned people want to comment on my regexp (ie tear it to
bits) I'd appreciated the feedback.
--
print reverse split ""=>q/,rekcah lreP rehtona tsuJ/;
-=G=-
web: http://www.fscked.co.uk icq: 66545079
------------------------------
Date: Tue, 19 Sep 2000 17:14:05 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: Split NS Log File
Message-Id: <x9Nx5.273395$1h3.5770006@news20.bellglobal.com>
Glyndwr <glynFOOdwr@fsckdeleteemed.co.uk> wrote:
: <fperkins@my-deja.com> wrote in message news:8q7umv$la5$1@nnrp1.deja.com...
:> I have a log file that I need to split in order to analyze the fields.
: I've never posted here before, so I'm expecting someone to come along in a
: few minutes and tell me this is rubbish. Still, I'll have a go :o)
:> 207.179.196.120 - - [31/Jul/2000:22:05:02 -0000] "GET / HTTP/1.0" 200
:> 737 "http://www.someurl.com/url.html" "Mozilla/4.06 [en] (Win98;
:> I)" "INTERSE=20724114964484603"
: Rather than a simple split, I would use a regexp and then get the bits from
: backreferences. Say the string is in $foo.
: $foo =~ /([\d\.]{15})[\s\-]*?\[(.*?)\]\s*"(.*?)".*"(.*)"\s*"(.*)"\s"(.*)"/;
: ($ip,$date,$request,$url,$browser,$foo) = ($1,$2,$3,$4,$5,$6);
: I haven't compiled this to test the regexp, so it might have some bloopers,
: but you get the idea.
: Actually, if any seasoned people want to comment on my regexp (ie tear it to
: bits) I'd appreciated the feedback.
The regex is nice, albeit thereis some dubious assumptions
(for example, 127.0.0.1 is a valid IP address and doesn't match your
/[\d.]{15}/ (oh, '.' in a [] is just that, a dot. no need to backlash)).
Myself, I prefer to do a couple of smallers regexes instead of one
big stomach-churning one (no offense to your code, but anything
that has twice as many backslashes than actual letters is bound to
be stomach-churning :). Here, I would have done:
$_ = <LOGFILE>; # read the line
( $ip ) = /^(\S+)/; # line begin with IP address
( $date ) = /\[(.*?)\]/; # first thing in brackets is the date
( $request, $url, $browser, $stuff ) = /".*?"/g; # all is quoted, yay!
Joy,
Yanick
--
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;
------------------------------
Date: Tue, 19 Sep 2000 18:36:11 +0100
From: "Glyndwr" <glynFOOdwr@FSCKdeleteEmeD.co.uk>
Subject: Re: Split NS Log File
Message-Id: <jsNx5.8429$ap5.148686@news6-win.server.ntlworld.com>
"Yanick Champoux" <yanick@babyl.sympatico.ca> wrote in message
news:x9Nx5.273395$1h3.5770006@news20.bellglobal.com...
> Glyndwr <glynFOOdwr@fsckdeleteemed.co.uk> wrote:
> : <fperkins@my-deja.com> wrote in message
news:8q7umv$la5$1@nnrp1.deja.com...
> :> I have a log file that I need to split in order to analyze the fields.
>
> : I've never posted here before, so I'm expecting someone to come along in
a
> : few minutes and tell me this is rubbish. Still, I'll have a go :o)
>
> :> 207.179.196.120 - - [31/Jul/2000:22:05:02 -0000] "GET / HTTP/1.0" 200
> :> 737 "http://www.someurl.com/url.html" "Mozilla/4.06 [en] (Win98;
> :> I)" "INTERSE=20724114964484603"
>
> : Rather than a simple split, I would use a regexp and then get the bits
from
> : backreferences. Say the string is in $foo.
>
> : $foo =~
/([\d\.]{15})[\s\-]*?\[(.*?)\]\s*"(.*?)".*"(.*)"\s*"(.*)"\s"(.*)"/;
> : ($ip,$date,$request,$url,$browser,$foo) = ($1,$2,$3,$4,$5,$6);
>
> The regex is nice, albeit thereis some dubious assumptions
> (for example, 127.0.0.1 is a valid IP address and doesn't match your
> /[\d.]{15}/
Hehe, hidden assumptions. Doncha just hate them? Good point though. I nearly
wrote
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
but decided it was too clumsy so ditched it :o)
>(oh, '.' in a [] is just that, a dot. no need to backlash)).
Ah, I didn't know that, although in hindsight it's obvious.
> Myself, I prefer to do a couple of smallers regexes instead of one
> big stomach-churning one (no offense to your code, but anything
> that has twice as many backslashes than actual letters is bound to
> be stomach-churning :). Here, I would have done:
Hehe, no offence taken. It could use spacing out and some comments, at
least.
> $_ = <LOGFILE>; # read the line
>
> ( $ip ) = /^(\S+)/; # line begin with IP address
> ( $date ) = /\[(.*?)\]/; # first thing in brackets is the date
> ( $request, $url, $browser, $stuff ) = /".*?"/g; # all is quoted, yay!
That is quite neat. Nice.
--
-=G=-
print join " ",reverse split /\s+/,'hacker. Perl another Just',"\n";
Web: http://www.fscked.co.uk ICQ: 66545073
------------------------------
Date: 19 Sep 2000 18:08:45 +0100
From: nobull@mail.com
Subject: Subroutines sharing a variable (was: Difference @ARGV[0] and $filepath=@ARGV[0])
Message-Id: <u97l88s40y.fsf@wcl-l.bham.ac.uk>
"FX" <FX@hasnomail.com> writes:
> Subject: Re: Difference @ARGV[0] and $filepath=@ARGV[0]
Your question is totally unrelated to the current thread - you should
start a new thread.
> I would like to use strict but i'm using :
[ snip two subroutines that share a variable ]
Declare the shared variable with a my() at the outermost scope.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 19 Sep 2000 12:10:10 -0400
From: Chad Williams <chad.williams@bellsouth.com>
Subject: system load analysis tools
Message-Id: <39C78FE2.2260623B@bellsouth.com>
I want to collect system load data (solaris 2.6 mostly) via korn shells
that do things like vmstat, iostat, etc. and then use perl to parse the
data into meaningful/user friendly formats.
I was thinking it would be nice to graph the data some how in .gifs .
Are there particular modules for this?
------------------------------
Date: Tue, 19 Sep 2000 19:06:30 +0200
From: "carma" <gamer@freegates.be>
Subject: Tutorial Perl?
Message-Id: <newscache$ap751g$kpi$1@news.freegates.be>
Where can I find one? For Free and in English or Dutch?
Plz help me
------------------------------
Date: 19 Sep 2000 13:04:28 -0400
From: steveo@panix.com (Steven M. O'Neill)
Subject: Re: Tutorial Perl?
Message-Id: <8q86as$aqb$1@panix6.panix.com>
carma <gamer@freegates.be> wrote:
>Where can I find one? For Free and in English or Dutch?
>Plz help me
http://www.google.com/search?q=perl+tutorial[+dutch]
--
Steven O'Neill steveo@panix.com
------------------------------
Date: Tue, 19 Sep 2000 15:59:31 GMT
From: mmonti@cswe.org (M. Monti)
Subject: Variable Handling
Message-Id: <39c78d59.11707897@va.news.verio.net>
I'm a beginner trying to create a 2-component search-engine type form.
Component 1: Radio buttons set up to determine which fields of a data
file to search on.
Component 2: Text field for keyword to find matches on.
My strategy was to set the values of radio buttons to indicate the
slice of the array to search on (Button A value=0..2, Button B=3..5) .
Ideally, the value would then get plugged in to the line where I use
the match command. But I can't get this to work. (I do get it to work
when I replace the variable with the slice it should be [i.e., 0..2].)
Do I misunderstand how to use the variables?
Here's what I mean:
...
# split and clean up query
@queryelems=split ("&",$query);
foreach $piece(@queryelems){
#clean up pieces
$piece=~ s/....=//g;
$piece=~ s/\+/ /g;
$piece=~ s/%(..)/chr(hex($1))/ge;
}
#declare variables for search
#note: i'm not sure this step is even necessary
#when I plug in $queryelems[0] below, it doesn't work, either
$ab=$queryelems[0];
$bc=$queryelems[1];
open(fl, "MastCand.txt");
$count=0;
while (<fl>) {
@list=split("\t",$_);
if ($list[$ab]=~m/$bc/i) {
print "Match found\n";
$count++;
}
}
close (fl);
if ($count==0) {
print "No Matches\n";
}
...
Mike Monti
Council on Social Work Education
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 4375
**************************************