[10093] in Perl-Users-Digest
Perl-Users Digest, Issue: 3685 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 10 19:08:02 1998
Date: Thu, 10 Sep 98 16:01:54 -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 Thu, 10 Sep 1998 Volume: 8 Number: 3685
Today's topics:
Re: Absolute and Relative paths <tchrist@mox.perl.com>
Re: Absolute and Relative paths (Abigail)
Re: Absolute and Relative paths <mark@waterware.com>
Re: Efficiency of subject line change program <rick.delaney@shaw.wave.ca>
forking in Win32 <rosholt@uiuc.edu>
Graphs <"jdcaraway@mindspring.com"@mindspring.com>
Re: Graphs <jbostwic@valinor.cargill.com>
Re: How do you hide the definition of a subroutine? (Abigail)
MD5 & Base 64 (Rob Fausey TA CompSci)
Re: MD5 & Base 64 (Maurice Aubrey)
Re: mod_perl looping :-(. <zenin@bawdycaste.org>
Not Spam! [was: For Sale: O'Reilly Perl Resource Kit - <vincent@compclass.com>
Re: Not Spam! [was: For Sale: O'Reilly Perl Resource Ki <rick.delaney@shaw.wave.ca>
Re: Objects & type checking <mark@satch.markl.com>
Re: Objects & type checking <eashton@bbnplanet.com>
Re: Passing file handles (Alastair)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 10 Sep 1998 21:01:28 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Absolute and Relative paths
Message-Id: <6t9en8$cpf$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
michael@holdendesign.com writes:
:I have to change all <a href> links from absolute paths to relative
:paths on roughly 5000 files. In the spirit of not reinventing the wheel
:I was wondering if anyone knew if there were scripts or modules out
:there that can assist with this.
--tom
#!/usr/bin/perl
use File::Find;
use URI::URL;
$DIR = shift || die "usage: $0 base [start]\n";
die "missing $DIR" unless -d $DIR;
$START = shift || $DIR;
die "missing $START" unless -d $START;
find ( \&fixup, $START );
sub fixup {
return unless /.html$/;
my $filename = $File::Find::name;
my $BASE = $filename;
$BASE =~ s,[^/]+$,,;
die "$file exists " if -e "$filename.orig";
local @ARGV = $filename;
local $^I = ".orig";
warn "@ARGV\n";
while (<>) {
s{
(
(HREF \s* = \s*)
(['"])
($DIR.*?)
\3
)
}{
my ($all, $first, $quote, $file) = ($1, $2, $3, $4);
if ( index($file, $DIR) == 0 ) {
my $rel = url("file:$file", "file:$BASE")->rel();
$rel =~ s/#$//;
$first . $quote . $rel . $quote;
} else {
$all;
}
}sgex;
} continue {
print;
}
}
--
"Incrementing C by 1 is not enough to make a good object-oriented language."
(M. Sakkinen, in "On the Darker Side of C++", ECOOP'88)
------------------------------
Date: 10 Sep 1998 21:28:08 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Absolute and Relative paths
Message-Id: <6t9g98$35$3@client3.news.psi.net>
Colin Kuskie (ckuskie@cadence.com) wrote on MDCCCXXXVI September MCMXCIII
in <URL: news:Pine.GSO.3.96.980910120848.27123B-100000@pdxue150.cadence.com>:
++ On Thu, 10 Sep 1998, Michael Holden wrote:
++
++ > I have to change all <a href> links from absolute paths to relative
++ > paths on roughly 5000 files. In the spirit of not reinventing the wheel
++ > I was wondering if anyone knew if there were scripts or modules out
++ > there that can assist with this.
++
++ I've never heard of a general purpose tool to do this. Given the
++ scope of the problem I doubt such a tool exists since it would
++ have to be really flexible and programmable.
++
++ Your best bet is to write a quick/dirty perl script to do this:
++
++ #!/usr/local/bin/perl -w
++
++ while (<>) {
++ next unless /<A HREF/; ##Skip unwanted lines
++ ($url) = /<A HREF="([^"]+)"/; ##grab the path
++ ##change the path to be what you want
++ s/<A HREF="([^"]+)"/<A HREF="$url"/;
++ print;
++ }
++
++ VERY IMPORTANT NOTES:
++
++ 1) It's case sensitive (A HREF).
++ 2) Assumes only HREF per line.
++ 3) Doesn't allow double quotes in the URL (not too crazy, but you
++ know).
++ 4) Works like a pipe: noabs file.html > file1.html
You forgot a few.
5) Assumes tag uses upper case tagname.
6) Assumes tag uses upper case attribute name.
7) Assumes HREF is the first attribute.
8) Assumes exactly one space between tag name and HREF attribute.
9) Assumes no space between HREF and the =
10) Assumes no space between = and attribute value.
11) Assumes attribute values is quoted.
12) Assumes double quotes are using for quoting.
Basically, the program might work in 0.0001% of the cases. If you're lucky.
use HTML::Parser. Even while HTML::Parser sucks, it will be far, far, far
better than the above approach.
Abigail
--
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s}
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))
------------------------------
Date: Thu, 10 Sep 1998 15:11:25 -0700
From: Mark Waters <mark@waterware.com>
To: michael@holdendesign.com
Subject: Re: Absolute and Relative paths
Message-Id: <35F84E8D.1ABEA442@waterware.com>
Michael,
I have had similar problems many times. I used to be the Director of
Internet Operations at www.golfweb.com and had over 100,000 HTML files
to keep track of. There were frequent requests to change something, such
as headers or footers, on every single page. Other usage examples
include changing all occurrences of foo.gif to bar.gif.
My solution was to rip through the file system with my 'fix' script. It
is nothing more than a string replacement script. The program optionally
searches all subdirectories. You can also set flags for what type of
files you want to test.
When it's done it will tell you how many files it looked at, how many it
modified and how many did not contain the "old" string. It is a lot of
fun to change 100,000 files in a matter of minutes!
One important flag to use is $test. If this flag is set, only a file
called test.html will be modified. It's a good idea to test your $old
and $new values before attacking your 5,000 files.
If some of your files already contain absolute paths you may want to add
some additional logic to test for that condition.
Hope this helps.
h2o
#!/usr/local/bin/perl5
# Written by Mark E. Waters
# WaterWare
# July 9, 1996
#
# This program modifies the footer of each htm and html file
#
# The subroutine dir is called recursively to walk all subdirectories,
# starting at the directory defined by $Pstart.
#
#
# define replacement strings
#
$old = "href=\"/";
$new = "href=\"www.waterware.com/";
print "old: $old \n new: $new \n\n";
#------------------------------
#
# set paramters for which files to edit
#
# 1 = true, 0 = false
#
$VERBOSE = 1; # display a list of processed files
$DEBUG = 0; # display debug messages
$subdirs = 0; # process all subdirectories
$test = 0; # process ONLY test.html
$index = 0; # process ONLY index.html
$html = 1; # process .html and .htm files
$cgi = 1; # process .cgi files
$pm = 1; # process .pm files
$pl = 0; # process .pl files
$cfg = 0; # process .cfg files
$log = 0; # process .log files
$txt = 0; # process .txt files
$all = 0; # process all files, regardless of extension
$h2o = 0; # process files that contain 'h2o'
$includes = ''; # process files that contain this string, ex: 'foobar'
#
# define files and paths
#
$Pstart = `pwd`;
chop($Pstart);
$Ftmp = "$Pstart/tmp\.$$";
# define counters
$MODcnt = 0;
$TESTcnt = 0;
if ($VERBOSE) {print "\nstarting directory: $Pstart\n\n";}
&dir($Pstart);
if ($VERBOSE) {
print <<EOF
Modified $MODcnt file(s).
Tested, but did not modify, $TESTcnt files(s)
EOF
}
exit 1;
#------------------------------------------------------------
# sub process - process a file to make the substitutions
#------------------------------------------------------------
sub process
{
local($filename) = @_;
open(FILE,$filename) || die "Can't open input file: $filename\n";
open(TEMP,">$Ftmp") || die "Can't open temp file: $Ftmp\n";
# save mode of input file
@stat = stat(FILE);
local($modified) = 0;
while ( <FILE> ) {
if ($_ =~ /$old/) {
# change old string to new string
s/$old/$new/g;
$modified = 1;
}
print TEMP "$_";
}
close(FILE);
close(TEMP);
if ($modified) {
if (rename($Ftmp,$filename)) {
++$MODcnt;
chmod($stat[2],$filename);
if ($VERBOSE) {print "modified: $filename\n";}
} else {
die "Died. Can't rename temp file back to $filename\n";
}
} else {
++$TESTcnt;
if ($VERBOSE) {print "tested: $filename\n";}
}
}
#------------------------------------------------------------
# sub dir - test all subdirectories
#------------------------------------------------------------
sub dir {
local($level) = "@_";
++$h;
local($hl) = "a$h";
local($name, $bigname);
if (opendir($hl,$level)) {
foreach $name (sort readdir($hl)) {
if ($name =~ /^\./) {next;}
if (-l $name) {next;}
$bigname = "$level/$name";
if ( -d $bigname && $subdirs) {
&dir($bigname);
} elsif ( -f "$bigname") {
if ($DEBUG) {print "file = $bigname\n";}
&testname($bigname);
}
}
} else {
print ERR "could not open $level\n";
}
closedir($hl);
return 1;
}
#------------------------------------------------------------
# sub testname - test the file name for the correct string
#------------------------------------------------------------
sub testname
{
local($filename) = @_;
if ($index || $test) {
if ($index && $filename =~ /index\.html$/) {&process($filename);}
if ($test && $filename =~ /test\.html$/) {&process($filename);}
} else {
if ($all) {
&process($filename);
} elsif ($html && ($filename =~ /\.htm$/ || $filename =~ /\.html$/))
{
&process($filename);
} elsif ($cgi && $filename =~ /\.cgi$/ ) {
&process($filename);
} elsif ($pm && $filename =~ /\.pm$/ ) {
&process($filename);
} elsif ($pl && $filename =~ /\.pl$/ ) {
&process($filename);
} elsif ($h2o && $filename =~ /\.h2o$/ ) {
&process($filename);
} elsif ($cfg && $filename =~ /\.cfg$/ ) {
&process($filename);
} elsif ($log && $filename =~ /\.log$/ ) {
&process($filename);
} elsif ($txt && $filename =~ /\.txt$/ ) {
&process($filename);
} elsif ($includes =~ /\w/ && $filename =~ /$includes/ ) {
&process($filename);
}
}
} # end of sub testname
Michael Holden wrote:
>
> Hello, fellow PERLers.
>
> I have to change all <a href> links from absolute paths to relative
> paths on roughly 5000 files. In the spirit of not reinventing the wheel
> I was wondering if anyone knew if there were scripts or modules out
> there that can assist with this.
>
> You can reply off-list if you want. My email address is
> michael@holdendesign.com.
>
> Thanks in advance!
>
> Michael
> "Don't stray off the path!" --Gandalf
--
---------------
Mark Waters
WaterWare
http://www.waterware.com/
Do or do not, there is no try. -- Yoda
------------------------------
Date: Thu, 10 Sep 1998 22:00:21 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Efficiency of subject line change program
Message-Id: <35F84D7C.EE294E98@shaw.wave.ca>
Sean McAfee wrote:
>
> In article <01bddce0$e261fee0$8395cdcf@hp-customer>,
> George H <george@tapestry.net> wrote:
> > if (/^Subject:/ && /\D(\d{6})\D/)
...
> if (/^Subject:/ && /\D(\d{6})(?!\d)/) {
...
> b) I altered your regex to allow for six-digit numbers which end the
> subject line; your original pattern would miss them.
Only if it were possible for the subject line to not have a line
terminator.
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: Thu, 10 Sep 1998 16:32:51 -0500
From: "David Rosholt" <rosholt@uiuc.edu>
Subject: forking in Win32
Message-Id: <6t9gjs$6or$1@vixen.cso.uiuc.edu>
What is the equivalent of the Unix fork command for Win32, and how do I use
it?
Thanks in advance.
------------------------------
Date: Thu, 10 Sep 1998 17:47:38 -0400
From: Daniel Caraway <"jdcaraway@mindspring.com"@mindspring.com>
Subject: Graphs
Message-Id: <6t9i1d$nms$1@camel15.mindspring.com>
Is it possible to create graphs with Perl? If so How?
------------------------------
Date: Thu, 10 Sep 1998 17:40:57 -0500
From: Jim Bostwick <jbostwic@valinor.cargill.com>
Subject: Re: Graphs
Message-Id: <35F85579.69F242A3@valinor.cargill.com>
Daniel Caraway wrote:
> Is it possible to create graphs with Perl? If so How?
>
Visit your favorite CPAN site and check out section 18:
18_Images_Pixmap_and_Bitmap_Manipulation_Drawing_and_Graphing
There are several choices. I usually use GifGraph.
hth,
-j
------------------------------
Date: 10 Sep 1998 21:30:42 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: How do you hide the definition of a subroutine?
Message-Id: <6t9ge2$35$4@client3.news.psi.net>
Bernard Cosell (bernie@fantasyfarm.com) wrote on MDCCCXXXVI September
MCMXCIII in <URL: news:35f92f00.515636801@ganymede.rev.net>:
++
++ Clearly I'm just not really understanding how this aspect of Perl
++ really works... what would the 'right' way be to do this kind of
++ function hiding?
undef &your_sub;
Abigail
--
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'
------------------------------
Date: 10 Sep 1998 21:13:19 GMT
From: fauseyr@mccc.edu (Rob Fausey TA CompSci)
Subject: MD5 & Base 64
Message-Id: <6t9fdf$72b$1@lawrenceville.mccc.edu>
Is it possible for MD5 to create a check sum in base64 instead of the
default hex format ? If so is there an example of this.
--
Rob Fausey.
''~``
( @ @ )
+------------------+ooO---(_)---Ooo+------------------+
| fauseyr@mccc.edu fauseyr@pt.cyanamid.com |
| Mercer County American Cyanamid |
| Community College Information Technology |
+----------------------------Oooo---------------------+
oooO ( )
( ) ) /
\ ( (_/
\_)
------------------------------
Date: Thu, 10 Sep 1998 21:19:01 GMT
From: maurice@hevanet.com (Maurice Aubrey)
Subject: Re: MD5 & Base 64
Message-Id: <slrn6vggi8.3h1.maurice@we-24-130-48-83.we.mediaone.net>
On 10 Sep 1998 21:13:19 GMT, Rob Fausey TA CompSci <fauseyr@mccc.edu> wrote:
>Is it possible for MD5 to create a check sum in base64 instead of the
>default hex format ? If so is there an example of this.
Can't you just take the MD5 hash and put it through MIME::Base64?
--
Maurice Aubrey <maurice@hevanet.com>
Underlying most arguments against the free market is a lack of belief
in freedom itself.
- Milton Friedman
------------------------------
Date: 10 Sep 98 22:22:12 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: mod_perl looping :-(.
Message-Id: <905466253.579075@thrush.omix.com>
[posted & mailed]
Eric Lee Green <eric@linux-hw.com> wrote:
: How can I make Apache and mod_perl quit looping when I have an error
: in my Perl script? Typical error: I write
: foo=$cgi->param('bar');
: rather than
: $foo=$cgi->param('bar');
use strict and -w ?
Make sure the first two lines of your script are:
#!/usr/local/bin/perl -w
use strict;
Then see if you still have this problem.
--
-Zenin (zenin@archive.rhps.org) From The Blue Camel we learn:
BSD: A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts. Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.) The full chemical name is "Berkeley Standard Distribution".
------------------------------
Date: Thu, 10 Sep 1998 14:20:17 -0700
From: Vincent Lowe <vincent@compclass.com>
Subject: Not Spam! [was: For Sale: O'Reilly Perl Resource Kit - WIN32]
Message-Id: <35F84291.4405BAD7@compclass.com>
Greg Bacon wrote:
>
> In article <6t4esf$v73$1@nnrp1.dejanews.com>,
> gregkeene@yahoo.com writes:
> : Send mail (REMOVE NOSPAMTODAY) to: gregkeeneNOSPAMTODAY@NOSPAMTODAYyahoo.com
> : for information.
>
> Funny, <A Href="MAILTO:gregbacon@yahoo.com">gregkeene@yahoo.com</A>, how
> you'd spam us but would be unwilling to receive spam in return. Go
> crawl back into whatever hole you came from.
>
...the original message was NOT spam. A post to this newsgroup offering
something for sale relevant to our interests is not what is not spam any
more than waiting for a pretty girl outside a class you know she takes
is stalking.
As a reader of this group I found interest in the fact that someone
wants to sell relevant literature soon after its publication. Was the
collection useless or disappointing to this reader?
The gratuitous posting of his email address was however, both rude and
offensive. Good work! I'll keep an eye out for other responsible posts
from you in the future.
---v
--
| vincent@compclass.com | "Birds rising in flight is a sign
| | that the enemy is lying in ambush..."
| 248.557.2754 | Sun Tzu
+--------------------------+-----------------------------------------
| Aqueduct Information Services http://www.aquecorp.com/vincent
------------------------------
Date: Thu, 10 Sep 1998 22:45:08 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Not Spam! [was: For Sale: O'Reilly Perl Resource Kit - WIN32]
Message-Id: <35F857FC.98F5EA2F@shaw.wave.ca>
Vincent Lowe wrote:
>
> ...the original message was NOT spam. A post to this newsgroup
> offering something for sale relevant to our interests is not what is
> not spam anymore than waiting for a pretty girl outside a class you
> know she takes is stalking.
Reason #9, "Why we need more all-girl schools".
> As a reader of this group I found interest in the fact that someone
> wants to sell relevant literature soon after its publication. Was the
> collection useless or disappointing to this reader?
Who cares? Just because you don't get enough spam in your email doesn't
mean everyone else wants to see it. Perhaps you should post a great big
list of all your interests to all the groups on Usenet so that everybody
can post stuff everywhere that will interest you.
--
Rick Delaney
rick.delaney@shaw.wave.ca
------------------------------
Date: 10 Sep 1998 16:55:47 -0400
From: Mark Lehrer <mark@satch.markl.com>
Subject: Re: Objects & type checking
Message-Id: <m3ogsnhelo.fsf@satch.markl.com>
Thanks so much!! This is just what I was looking for.
Mark
mcafee@waits.facilities.med.umich.edu (Sean McAfee) writes:
...
> >I agree, this is my first OO Perl project so I don't know the
> >differences well, yet. The tutorials haven't done a good job of
> >explaining them.
>
> >I learned that it isn't possible to have two methods of the same class
> >with the same name; which I'll assume means that I can have only one
> >constructor per class.
>
> No, you can have as many constructors as your want; they just have to have
> different names. Any subroutine which returns a new object is a
> "constructor":
>
> package foo;
>
> sub new_1 {
> my $pkg = shift;
> bless [ @_ ], $pkg;
> }
...
------------------------------
Date: Thu, 10 Sep 1998 21:20:07 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: Objects & type checking
Message-Id: <35F84028.AF8EC33E@bbnplanet.com>
Mark Lehrer wrote:
> Thanks so much!! This is just what I was looking for.
Sean, that was indeed well done. Mark, this was covered in the perltoot.
Peruse it again as I found it helpful and always recommend it. Good
luck.
e.
------------------------------
Date: Thu, 10 Sep 1998 21:53:50 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: Passing file handles
Message-Id: <slrn6vgma7.4h.alastair@calliope.demon.co.uk>
M.J.T. Guy <mjtg@cus.cam.ac.uk> wrote:
>cs - Elton Kong <cselton@hkp.hk> wrote:
>>Hi!
>>
>>I would like to know how I can pass a file handle to a sub-routine.
>>I'm played with different syntax combinations to no success. Could
>>anyone help? Thanks!
>
>Hmm.. let's see:
>
>perldoc -q filehandle
That doesn't work for me - has perldoc been updated for 5.005?
--
Alastair
work : alastair@psoft.co.uk
home : alastair@calliope.demon.co.uk
------------------------------
Date: 12 Jul 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 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 3685
**************************************