[7003] in Perl-Users-Digest
Perl-Users Digest, Issue: 628 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 18 05:47:22 1997
Date: Wed, 18 Jun 97 02:02:07 -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 Wed, 18 Jun 1997 Volume: 8 Number: 628
Today's topics:
GD: Automatic X,Y replacement cwt1959@rit.edu
getpwnam breaks sockets-- why? kessler@dfacades.com
Re: getting username and password <ajohnson@gpu.srv.ualberta.ca>
Re: How to change code using deprecated features? (M.J.T. Guy)
How to get browser window size? <zonycat@flash.net>
Re: Interesting (?) problem forking from cgi script <rootbeer@teleport.com>
libwww for Win32 <howard.yen@mci2000.com>
limit to record size? (Darwin O.V. Alonso)
Re: LOG base 10 operator (M.J.T. Guy)
Re: LOG base 10 operator <eike.grote@theo.phy.uni-bayreuth.de>
Re: Mail-Filter (Magnus Bodin)
Re: need help with "strict" <rootbeer@teleport.com>
Re: no cache <rootbeer@teleport.com>
OFFSET option for 'sysread' and 'syswrite' in 5.002 for (delete LOCALHOST to reply)
Re: Perl 5.004 binaries for Windows 95 <wm_n00@tarrcity.demon.co.uk>
Re: PERL Amiga..... <dickow@uidaho.edu>
Re: Perl and htpasswd (Magnus Bodin)
Re: perl joke of the day ? (Steffen Kluge)
Re: Perl Patterns for CGI (M.J.T. Guy)
Re: Problem using Net::FTP behind a firewall (Magnus Bodin)
Re: Return Value of push, Perl 4 vs. 5 (M.J.T. Guy)
Re: RFD: comp.lang.perl reorganization (A. Deckers)
Re: run-time eval efficiency question (M.J.T. Guy)
Re: Setting a variable for both split and join... <merlyn@stonehenge.com>
Re: Small prog., Large file, core dump (Sylvain Robitaille)
Re: Sorry another regex question - parsing HTML anchors <flg@vhojd.skovde.se>
Re: Sorry another regex question - parsing HTML anchors (Helmut Jarausch)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 15 Jun 1997 07:41:16 -0600
From: cwt1959@rit.edu
To: cwt1959@rit.edu
Subject: GD: Automatic X,Y replacement
Message-Id: <866378006.25329@dejanews.com>
Perl folks:
Thank you for all of your response. I realize that GD and HTML can not go
together - however I could make seperate scripts but that's another story.
Ok - there is this small problem that everyone overlooked - it was because
of the confusion with the HTML LANGUAGE included in the same GD script.
So here, I have removed the HTML language and replaced them in another
script.
What I want to do with THIS GD script is to replace the coordinates of an
X,Y automatically, depending on what the browser selected. This will not
work. Look at line 29 closely and notice that I typed in $XY{xandy} so
it could look for the name/value and replace it with a number (selected
by the browser) automatically. The funny part is, if I type in "345,80"
manually and then exectue this script - I get the image output on the
page - but not the "$XY{xandy}". Can anyone here tell me why this
returns a bad gif image. Here's the script:
--------------------------
1: push (@INC, "cgi-bin");
2: require("cgi-lib.pl");
3:
4: &ReadParse(*XY);
5:
6: use GD;
7:
8: $| = 1;
9:
10: $FileIn1 = "usa.gif" unless ($FileIn1 = $ARGV[0]);
11: $FileIn2 = "x.gif" unless ($FileIn2 = $ARGV[0]);
12: $File = "\&STDOUT" unless ($File = $ARGV[1]);
13:
14: print "Content-type: image/gif\n\n";
15:
16: open(USA, "< c:\\httpd\\cgi-bin\\temp\\usa.gif") || die;
17: binmode USA;
18: $USAmap = newFromGif GD::Image(USA) || die;
19: close (USA);
20:
21: open(x, "< c:\\httpd\\cgi-bin\\temp\\x.gif") || die;
22: binmode x;
23: $Xspot = newFromGif GD::Image(x) || die;
24: close (x);
25:
26: $white = $Xspot->colorClosest(255,255,255);
27: $Xspot->transparent($white);
28:
29: $USAmap->copy($Xspot,$XY{xandy},0,0,25,25);
30:
31: if ($USAmap->gif($File)) {}else{}
32: if ($Xspot->gif($File)) {}else{}
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Wed, 18 Jun 1997 03:36:14 -0600
From: kessler@dfacades.com
Subject: getpwnam breaks sockets-- why?
Message-Id: <866622207.27326@dejanews.com>
Hello Socket Gurus,
I've discovered on solaris 2.5.1, perl 5.003, that my perl-based web
server can't read from a socket connection, if the socket
is established after a call to getpwnam. (It works fine otherwise...these
are internet domain sockets ala Camel p353)
According to man pages on solaris, that's because getpwname is
non-reentrant (my guess here), and messes up multithreading. However, the
same program WORKS when I run it from perl -d!! Anyhow, Perl isn't
multithreading yet anyhow, right?
What gives? Is there any other way to getpwnam that won't mess
up sockets? There's apparently a reentrant getpwname_r, but I can't
see how to cleanly call that from perl, and maybe that's not an answer
anyhow.
Any body have a solution?
TIA,
Will Kessler
kessler@dfacades.com
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Sat, 14 Jun 1997 06:12:06 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: getting username and password
Message-Id: <33A27C86.1A46229@gpu.srv.ualberta.ca>
Mickey wrote:
>
> I am trying to read in usernames and passwords from a dummy passwd file.
> Using a while loop, I can get each passwd entry into a variable. Is there
> some easy way to extract just the username and password.
>
> My code so far:
>
> while($entry = <PASSWD>){
> ($user,$pass)=split(":", $entry) #This didn't work
>
> <Rest of routine>
>
aside from your lack of a semi-colon in the second line there,
it works for me. However, you can simplify it a bit by not
using assignment in the condition, and having split operate
on the default $_.
while (<PASSWD>) {
($usr,$pass)=split /:/;
print "$usr $pass\n"; #or whatever
}
are you running with -w to warn of problems? did you check
the open() function's return when you opened PASSWD?
What exactly happens when your program "doesn't work"?
regards
andrew
------------------------------
Date: 15 Jun 1997 14:25:42 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: How to change code using deprecated features?
Message-Id: <5o0u16$g9k@lyra.csx.cam.ac.uk>
In article <5ns24u$8vj$1@cas.org>, <lvirden@cas.org> wrote:
>A program I am using generates the warning message:
>
>Use of $* is deprecated at file.pl line 1317.
>
>Sure enough, at line 1317 I see the line
>
> $* = 1; # Turn on multiline searches
>
>What is the equivalent action to perform under Perl 5.004 for this
>capability?
Setting $* = 1 has the same effect as adding /m to all regexs within its
scope. So just do that. (But then your script won't be perl4
comaptible.)
Mike Guy
------------------------------
Date: Tue, 17 Jun 1997 23:12:40 -0700
From: Zonycat <zonycat@flash.net>
Subject: How to get browser window size?
Message-Id: <33A77C58.6ABE@flash.net>
I am trying to get the size of my browser window or anybody's browser
window that displays my WEB page. Is there an environmental variable or
cookie I could look at to see the window size?
I am trying to dynamically resize my images I display depending on the
window size. Basically different people have different screen sizes.
Any help will greatly be appreciated on finding the window size.
Dennis
------------------------------
Date: Sun, 15 Jun 1997 06:06:41 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Anthony Ciarochi <ciarochi@pe.net>
Subject: Re: Interesting (?) problem forking from cgi script
Message-Id: <Pine.GSO.3.96.970615060233.10052D-100000@kelly.teleport.com>
On 15 Jun 1997, Anthony Ciarochi wrote:
> Soooo, how DO you launch a perl script from a web page which launches a
> server process which must stay up after the original script exits and
> not stall the web page?
This is really not a Perl question, since the answer is the same if you
program in C, so you should find the answer in (the FAQ of) a newsgroup
about servers or CGI, but I'll tell you anyway: After a fork, the
filehandles STDIN, STDOUT, and STDERR are normally open in both the parent
and child processes. The server can't consider your process done until
those filehandles are closed. So if the child process closes them when it
starts, and if the parent process exits soon thereafter (thereby closing
the handles) all should be well.
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Sun, 15 Jun 1997 06:39:01 -0700
From: Howard Yen <howard.yen@mci2000.com>
Subject: libwww for Win32
Message-Id: <33A3F075.71C7@mci2000.com>
Is there a version (or some has one) of libwww for
Win32 (Win95)?
I have perl install on my Win95 (from activeware
http://www.perl.htp.com)
I have also download libwww5.07 for unix. i cannot seem to
make it work under Win95 someone help me her?
hy
------------------------------
Date: 13 Jun 1997 23:47:15 GMT
From: dalonso@u.washington.edu (Darwin O.V. Alonso)
Subject: limit to record size?
Message-Id: <5nsm63$ptk@nntp6.u.washington.edu>
It there a limit to the length of a record that perl can handle?
Is there a way to reset that limit?
Thanks,
Darwin
------------------------------
Date: 18 Jun 1997 08:36:55 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: LOG base 10 operator
Message-Id: <5o86n7$d3d@lyra.csx.cam.ac.uk>
Larry D'Anna <ldanna@ix.netcom.com> wrote:
>
>10 ** 1 = 10
>therefore
>log(10) = 1
Not in my perl, it ain't:
print log(10)
gives
2.30258509299405
Mike Guy
------------------------------
Date: Wed, 18 Jun 1997 09:02:41 +0200
From: Eike Grote <eike.grote@theo.phy.uni-bayreuth.de>
Subject: Re: LOG base 10 operator
Message-Id: <33A78811.41C6@theo.phy.uni-bayreuth.de>
Larry D'Anna wrote:
>
> Mark Contois wrote:
>
> > Michael J. Rocchetti wrote:
> >
> > > Does anyone know how to take the log base 10 of a number using PERL?
> >
> > log($number)/log(10)
> >
> > Works every time.
>
> 10 ** 1 = 10
> therefore
> log(10) = 1
> therefore
> log($number)/log(10) = log($number)
>
> :-)
Really?
2.71828182845905... ** 2.30258509299405... = 10
therefore
log(10) = 2.30258509299405
therefore
log($number)/log(10) = 0.434294481903252*log($number)
Bye, Eike
--
======================================================================
Eike Grote, Theoretical Physics IV, University of Bayreuth, Germany
----------------------------------------------------------------------
e-mail -> eike.grote@theo.phy.uni-bayreuth.de
WWW -> http://www.phy.uni-bayreuth.de/theo/tp4/members/grote.html
http://www.phy.uni-bayreuth.de/~btpa25/
======================================================================
------------------------------
Date: Wed, 18 Jun 1997 06:34:08 GMT
From: Magnus.Bodin@tychonides.se (Magnus Bodin)
Subject: Re: Mail-Filter
Message-Id: <33aa8035.50991361@news1.telenordia.se>
David Capelle <dc@xmp.priconet.de> wrote:
>Hi!
>
>I'm trying to write a Mail Filter in Perl5. It is supposed to remove Mails
>fom /var/spool/mail/user. How can I remove lines from a file?
>
If you are just a user, then the better way is to set your .forward
file to forward your mail to a program as stdin. Ask your local
sysadmin or check the sendmail book.
If you ARE sysadmin, you should know this.
You can deliver mail directly to programs in the aliases file of
sendmail. Or define a new local deliver method for e.g. a subdomain.
Check comp.mail.sendmail and the bat-book sendmail for this.
regards,
magnus
PS. Also check out procmail, it's a real mail filter.
------------------------------
Date: Sun, 15 Jun 1997 06:01:47 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Bob Berman <rjberman@mindspring.com>
Subject: Re: need help with "strict"
Message-Id: <Pine.GSO.3.96.970615055854.10052B-100000@kelly.teleport.com>
On Sat, 14 Jun 1997, Bob Berman wrote:
> Why does this give me an error?
> use strict;
> { package testpkg;
>
> sub connect {
> my($drh, $host, $dbname, $junk, $attrib )= @_;
>
> my $key;
> foreach $key ( keys %$attrib ) {
> Can't use string ("bob4") as a HASH ref while "strict refs" in use at
> strict.pl line 8.
You're passing 'bob4' as $attrib, then using it as a hash reference in
%$attrib. Perl would look for %bob4, but strict forbids you to specify
variable names as (soft) references. You either want to use 'no strict
refs' in that block to allow that or, better, to pass a hash reference
there.
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Sun, 15 Jun 1997 06:09:59 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Dennis A. Dean II" <dean@zeus.bwh.harvard.edu>
Subject: Re: no cache
Message-Id: <Pine.GSO.3.96.970615060712.10052E-100000@kelly.teleport.com>
On Sat, 14 Jun 1997, Dennis A. Dean II wrote:
> I know there is a no cache directive in httpd, ... I just don't know
> where to put it.
Maybe you should check in (the FAQ of) a newsgroup about httpd, servers,
CGI, or something similar. Since the answer to your question would be the
same whether you use Perl or C, it's not really a Perl question, is it?
(Although if you're using Perl's CGI.pm module, you might see whether its
docs touch upon your needs.) Thanks!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 13 Jun 97 12:37:40 EDT (-0400)
From: zyx@LOCALHOSTcrl.com (delete LOCALHOST to reply)
Subject: OFFSET option for 'sysread' and 'syswrite' in 5.002 for OS/2
Message-Id: <866223460.107@bellsouth.net>
I use 'sysread' and 'syswrite' to create and manipulate
a binary file one byte at a time. The file is opened for
read and write using 'sysopen'. I have no problems reading
and writing if I read from or write to it sequentially,
that is, manipulate it without using the OFFSET parameter.
I would like to access it non-sequentially and update it
in-place using the OFFSET parameter. But when I do a
'sysread' of 1 byte using OFFSET, I always get a null byte
(\000) and no error. A 'syswrite' using OFFSET does not
write anything to the file but neither does it return an
error.
I am running OS/2 3.0 and I am using perl 5.002 (and cannot
upgrade to 5.003 or 5.004 at the present time).
Any suggestions? As a workaround, I read the entire file
of 65536 bytes into a 65536-element array, manipulate it
there, and write it out periodically. This sucks memory
and reduces the number of concurrent instances of the job
that I can run.
------------------------------
Date: Sun, 15 Jun 1997 12:28:48 +0100
From: Wm <wm_n00@tarrcity.demon.co.uk>
Subject: Re: Perl 5.004 binaries for Windows 95
Message-Id: <$WpU$KAwH9ozEwDK@tarrcity.demon.co.uk>
Fri, 13 Jun 1997 20:04:19 <33a19228.113599@news.demon.co.uk>
Paul Moore <gustav@morpheus.demon.co.uk> posted...
<snip>
>I simply don't have the time at the moment to get this right.
>Especially as I don't begin to understand what's going on in the
>make/MakeMaker complexities of a perl build...
>
>Is anybody able to offer a pre-built distribution for Windows 95? It's
>the only way I'm likely to get this working...
Try http://www.ActiveWare.com/ its actually for Win32 (NT and Win95).
With the documentation that comes with it you will also find details
about the Win32 mailing lists.
--
Wm ... did you know? My spell checker wants tarrcity to be atrocity.
------------------------------
Date: 15 Jun 97 22:46:18 -0800
From: Bob Dickow <dickow@uidaho.edu>
Subject: Re: PERL Amiga.....
Message-Id: <789.7105T1366T937@uidaho.edu>
>Anyone out there using PERL on AMIGA?
>or know if there is a PERL 5 compiler for WIN95/3.1/MSDOS
>thanks
I am using PERL 5.003 on an Amiga, and I think 5.004 is
available. Get PERL from Aminet:
http://ftp.wustl.edu/pub/aminet/dev/ade/perl.lha
You might also be interested in AWS (Amiga Web
Server), which works great and you can run it to act
as a server to develope your cgi scripts without
having to be logged on anywhere. Try www.omnipresence.com
for this little hummer.
***********************************************//*
* Bob Dickow (dickow@uidaho.edu) \\// *
* Associate Professor of Horn/Theory/Composition *
* Lionel Hampton School of Music/Univ of Idaho *
* URL: http://www.uidaho.edu/~dickow/ *
**************************************************
------------------------------
Date: Wed, 18 Jun 1997 05:59:17 GMT
From: Magnus.Bodin@tychonides.se (Magnus Bodin)
Subject: Re: Perl and htpasswd
Message-Id: <33a775cf.48329944@news1.telenordia.se>
Josh Keller <dragon_clan@usa.net> wrote:
>I would like to make a perl script that adds a username and password to
>my .htpasswd file by running htpasswd off the Linux server. Is this
>possible? If so how do I do this?
>
>Thanks,
>Josh Keller
>harley@aracnet.com
>dragon_clan@usa.net
There is one "not-so-simple" solution which in other hand do not
require modules at all. Like this:
--- cut here -------
# usage: &append_pass(<filename>,<user>,<pass>);
#
sub append_pass {
($file,$user,$pwd)=@_;
$salt=&saltchar+&saltchar;
$cryptpwd=crypt($pwd,$salt);
open(FILE,">>$file");
print FILE "$user:$cryptpwd\n";
close(FILE);
}
# returns a "random" saltchar
sub saltchar {
# salt should consists of [A-Za-z0-9./]
# saltchar is by the way kinda joke for swedes:
# salt tumblers is called saltkar..
$rc=rand(62);
if ($rc<25) { $rc+=65; } # 0-24 goes A-Z
elsif ($rc<50) { $rc+=72; } # 25-49 goes a-z
else { $rc-=4; } # 50-61 goes ./0-9
$rc;
}
example:
&append_pass('.htaccess','reinar','xyzzy');
--- cut here -------
There also a more elegant solution given by
Randal Schwartz <merlyn@stonehenge.com>
1997/05/10
Here:
use HTTPD::UserAdmin;
HTTPD::UserAdmin
->new(Path => '/Path/to/directory')
->add('reinar','xyzzy');
which even handles the locking and everything all behind the scenes.
HTTPD::UserAdmin is in the CPAN (of course).
------------------------------
Date: 18 Jun 1997 16:01:36 +1000
From: kluge@fujitsu.com.au (Steffen Kluge)
Subject: Re: perl joke of the day ?
Message-Id: <5o7tk0$gs8$1@syd0128.fujitsu.com.au>
In article <Pine.LNX.3.95.970616112952.28669F-100000@adams.patriot.net>,
Nick Vargish <nav@patriot.net> wrote:
>
>if (length(@opyrf[$idx]) > 0) ...
>
>I spent a whole day last week fixing lines like this in a 90K "filter"
>that was handed to me by my current contract.
What did you "fix" about that line??
Cheers
Steffen.
--
Steffen Kluge <kluge@fujitsu.com.au>
Fujitsu Australia Ltd
Keywords: photography, Mozart, UNIX, Islay Malt
--
------------------------------
Date: 15 Jun 1997 20:38:00 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Perl Patterns for CGI
Message-Id: <5o1jr8$31v@lyra.csx.cam.ac.uk>
Craig Berry <cberry@cinenet.net> wrote:
>David Tauzell (tauzell@math.umn.edu) wrote:
>: A great way of handling errors in cgi scripts is to eval everything and
>: also redirect standard error. This way, at the end of your *normal*
>: processing and output you print out the standard error. In addition,
>: any fatal errors can be caught by the eval.
>
>The problem is that evals have a very high processing-overhead cost. For
>a CGI script that won't get hit frequently this needn't be a concern, but
>on a 'hot' page the cpu can add up fast.
Only eval EXPR has a high overhead. The extra cost of eval BLOCK
is negligible.
Mike Guy
------------------------------
Date: Wed, 18 Jun 1997 06:28:45 GMT
From: Magnus.Bodin@tychonides.se (Magnus Bodin)
Subject: Re: Problem using Net::FTP behind a firewall
Message-Id: <33a97fbd.50871539@news1.telenordia.se>
kpur@jet.uk (Krishan Purahoo) wrote:
>Hi,
> I am trying to use Net::FTP to ftp from behind a firewall, using the
>following code.
>
> 1 #!/usr/local/bin/perl
> 2
> 3 use Net::FTP;
> 4
> 5 $ftp = Net::FTP->new("some.site", Firewall => "firewall", Timeout => 10);
> 6 $ftp->login("anonymous", "email_address");
> 7 print $ftp->pwd,"\n";
> 8 print $ftp->ls('-l');
> 9 $ftp->quit;
>
>
>When I run the above code, I get the following error message:
>
>Can't call method "login" without a package or object reference at line 6
>
If you'd try with a normal ftp-program, I suppose the ftp-client will
get the "no route to host"-error.
You should try to go in to "passive ftp mode" (see protocol spec for
details), see man page from pasv() and further.
It all depends on how your firewall works. If you have a
just-blocking-some-tcp-and-udp-ports-and-packages firewall, then
passive ftp will probably work (if the ftp-port is open out :-),
but if you use masked ip-numbers with e.g. a faked ip-set on the
inside, then it will not work. Try passive ftp first.
/magnus
------------------------------
Date: 15 Jun 1997 14:19:27 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Return Value of push, Perl 4 vs. 5
Message-Id: <5o0tlf$g3r@lyra.csx.cam.ac.uk>
Mark Stallard <mrs@cae091.ed.ray.com> wrote:
>I've been using Perl 5.003 whenever I can, but occasionally forced
>to revert to Perl 4.035. Perl 4 is still great, but I usually find
>myself giving up some nice features of Perl 5.
>
>One exception is push's return value. I was playing with one-liners
>yesterday, and Perl 4 did what I wanted, but not Perl 5.
>
>In Perl 4, push returned the first value of the list it pushed; a
>null value there was nothing to push. Perl 5, however, returns the
>scalar() value of @inc regardless of whether any values were pushed.
>As a result, my Perl 5 test printed output for every input line fol-
>lowing the first successful push.
>
>The 2nd edition of the Camel Book doesn't appear to mention this
>behavior, nor could I find it in the FAQ's. Did I discover a
>Perl 5 bug, an unintended feature of Perl 4, or just another
>4-to-5 trap?
What behaviour were you expecting? Neither the perl4 nor the perl5
man page say anything about the result value from push, so if you
are using it, you are in a serious state of sin.
While perltrap doesn't contain a remark of the form "Things which are not
defined may be not defined in different ways between Perl 4 and Perl 5",
you should be able to guess that for yourself. :-)
Mike Guy
------------------------------
Date: 13 Jun 1997 18:52:55 GMT
From: deckers@man.ac.uk (A. Deckers)
Subject: Re: RFD: comp.lang.perl reorganization
Message-Id: <slrn5q35o3.kj4.deckers@news.rediris.es>
[NB: Followup-To: news.groups]
In <s4vwwnyiw2q.fsf@et-sun4.uk.jpmorgan.com>
Anthony Heading <heading_anthony@jpmorgan.com> wrote:
[...]
>>> CHARTER: comp.lang.perl.data-structure
>>> Submission address: clp-data@perl.com
>>
>>> CHARTER: comp.lang.perl.inter-process
>>> Submission address: clp-interprocess@perl.com
>There's a lack of consistency between the newsgroup and the submission
>address, which seems pointless. Further, the names are long-winded
>and out of kilter with the de-facto general convention for newsgroups
>of using short unambiguous abbreviations which don't require one to
>remember punctuation conventions.
I'm all ears for possible alternatives. However, I have to say that
personally I don't consider this a major problem, and whichever way you
cut it, there's going to be some arbitrariness involved, so these
seemed as good a choice as any other.
Would these be any better?
clp-dsc@perl.com # clp.data-structure
clp-ipc@perl.com # clp.inter-process
clp-prog@perl.com # clp.programmer
clp-re@perl.com # clp.regex
(The abbreviations follow the convention used in the man pages as close
as possible.)
>More specifically, an example of an alternative...
>The manual pages already provide a subdivision of language topics, and
>it's not unreasonable IMHO to expect people posting questions about
>inter-process communication to at least be aware of the perlipc manual
>page/pod documentation. So what is wrong with comp.lang.perl.ipc?
Because the consensus seems to be that obscure abreviations should be
avoided if at all possible. By your argument the groups would end up
being called:
comp.lang.perl.dsc
comp.lang.perl.ipc
comp.lang.perl.programmer
comp.lang.perl.re
IMO this would confuse a great many people. Certainly more people than
would be confused by the currently proposed names.
Alain
--
Introduction to news.groups:
<URL:http://www.cybernothing.org/faqs/new-users-please-read.txt>
Guidelines for Usenet Group Creation:
<URL:ftp://rtfm.mit.edu/pub/faqs/usenet/creating-newsgroups/part1>
------------------------------
Date: 15 Jun 1997 20:31:19 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: run-time eval efficiency question
Message-Id: <5o1jen$2j8@lyra.csx.cam.ac.uk>
In article <33A06E0F.452F@calarts.edu>, Jason Lamport <web@calarts.edu> wrote:
>Does anyone know just how intelligent perl is about not recompiling code
>passed to an eval function when that code doesn't need to be
>recompiled? e.g. I know that in
>
>foreach (1..10) { eval 'print "Hello!";'; }
>
>the 'print "Hello!";' gets compiled at runtime; but does it get compiled
>once at runtime, or does it get compiled ten times?
AFAIK, Perl will compile this ten times.
> What about:
>
>foreach (1..10) { eval $some_code; }
Also ten times.
>Since $some_code is never modified in the loop, Perl _could_ compile it
>just once -- but does it?
No, it couldn't, in general. The compilation may have side effects
(i.e. if it contains BEGIN {} blocks).
> What about:
>
>$f1 = sub { eval $some_code; }
>foreach (1..10) { &$f1; }
Also ten times - why would the subroutine make any difference?
>or
>
>$f1 = eval "return sub { $some_code }";
>foreach (1..10) { &$f1; }
Now you're getting warmer. This is of course only compiled once.
This paradigm (with the redundant "return" removed) is recommended in
both the man pages and in the FAQ.
The final form you might consider is to put the whole loop in the eval:
eval "foreach (1..10) { $some_code }";
This will again only compile once and is marginally more efficient than
the preceding style, tho' the difference is probably tiny in practical
cases. For more complicated examples, you tend to get a bad attack
of backslash-itis, so I usually prefer the preceding. For example, if
your limits were $start and $end, you'd have to write
eval "foreach (\$start..\$end) { $some_code }";
And finally, remember to use Benchmark.pm to check if your intuitions
about efficiency of different methods are correct.
Mike Guy
------------------------------
Date: 14 Jun 1997 12:36:39 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Prince Mystery <mystery@itis.com>
Subject: Re: Setting a variable for both split and join...
Message-Id: <8ciuzh9dtk.fsf@gadget.cscaper.com>
>>>>> "Prince" == Prince Mystery <mystery@itis.com> writes:
Prince> I think you have to run $SEPARATOR through the quotemeta() func before
Prince> running it through split, ie:
Prince> @text = split(/quotemeta($SEPARATOR)/,$text);
No. quotemeta() is an ordinary function, and does not work inside
"double-quoted" string contexts, like regex. You need to either
do the work before you get into the string:
$quoted = quotemeta($SEPARATOR);
@text = split /$quoted/, $text;
or use the equivalent \Q modifier inside the string:
@text = split /\Q$SEPARATOR/, $text;
However, beware that both of these cause the regex to be recompiled
each time you hit this chunk of code. Not noticeable if you do that
ten times, but very sloooooowwww if you have to do that 10,000 times.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 443 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 16 Jun 1997 03:08:30 GMT
From: sp_robi@alcor.concordia.ca (Sylvain Robitaille)
Subject: Re: Small prog., Large file, core dump
Message-Id: <slrn5q9bhc.5ao.sp_robi@Elvira.home>
On Thu, 12 Jun 1997 11:15:59 -0400, Jennifer R. Amon <jamon@apk.net> wrote:
>
>I have a very small program which strips trailing blanks from
>the quoted, comma-delimited strings in a data file.
>
> . . .
>
>The program looks like this:
>
> #!/usr/local/bin/perl $infile = "PARTREV.txt";
>
> open(IN_FILE, $infile);
> open(OUT_FILE, $outfile);
I think your problem is right here. You haven't told it what to use as an
$outfile, (unless there's some code fragment(s) missing? For the sake of this
followup, I'll assume not).
> while ($line = <IN_FILE>)
> {
> $line =~ s/ +"/"/g;
> printf OUT_FILE $line;
> }
> close(OUT_FILE);
> close(IN_FILE);
>
>The input file has 40000+ lines.
>The program dies consistently on line 14589.
>This is true even if I edit the input file and delete line
>14589 and a few lines before and after that line. The program
>then dies on the "new" line 14589.
Perl buffers it's output. No doubt this is why you don't see the error sooner.
If you change you #! line to read '#!/usr/local/bin/perl -w', then Perl will
point out such oversites to you, rather than try to run the program.
>Suggestions?
Hope the ones I've made help you out. Enjoy! :-)
>_______________________________________________________________________
>I love music, nature, animals, books, antiques, children, family,
>travel, and Thin Mint Girl Scout cookies! :-)
>_______________________________________________________________________
7 outta 9 ain't bad... :-)
--
----------------------------------------------------------------------
Sylvain Robitaille sp_robi@alcor.concordia.ca
Assistant to the System Manager
Computing Services Department
Concordia University Montreal, Quebec, Canada
----------------------------------------------------------------------
------------------------------
Date: 18 Jun 97 07:36:28 GMT
From: "Fredrik Lindberg" <flg@vhojd.skovde.se>
Subject: Re: Sorry another regex question - parsing HTML anchors??? Interesting though...
Message-Id: <01bc7bba$4ad5f280$e20f10c2@odens.di.vhojd.skovde.se>
topaz56@one.net wrote in article
<33a73efa.128472207@news.mindspring.com>...
>
> I can't figure this out, even after reading (sporadically) through
> understading regular expressions. What operator matches
> anything akin to * in unix? Is it *? or (*) or .*? What I'm trying
> to do is to take input ($data below) & simply parse out the HTML
> anchor, plus the intervening text, ie...
>
> <a href="http://company.com">Company</a>
>
> I'd like to dump the url and the name into separate variables
Hi.
The * in regexps is _not_ the same as the * in various shells.
The * in regexp is a quantifier. It says how many times the
previous regexp need to match. In the case of * it need
to match 0 times (but can match as many as possible).
There are other quantifier like the + (needs to match at least 1)
and ? (which needs to match 0, but can match 1), and also
the {min,max} construct.
For a good description of perls regexp I would suggest you
read Tom Christiansens very informativ document available
at http://www.perl.com/perl/everything_to_know/regexps.html
Which also discusses some advance techniques (using HTML
tags as example data).
Other useful resource might be Randal L. Schwartz's columns
from the Unix Review magazine. There are several good articles
to be found there (not necessarily about regexps though).
You find them at http://www.stonehenge.com/merlyn/UnixReview/
Of course you should also read the perlre man page.
As for your problem at hand, maybe this could solve your problem?
I dont claim this to be 100% perfrect as regard to <A HREF> tags
since I dont know the spec enough, but I ran some random tests on
it which seemed to work out ok.
#!/usr/bin/perl -w
#
# I slurp the whole file into one string to avoid
# stumble on tags splitting over several lines.
$text = join '', <>;
# Loop over the string as long as we find a match..
# The regexp needs some modifiers (the /gxsi) in the end
# to function properly.
#
# The /g makes the loop pickup where the previous left off, returning
# true as long as there is a match.
# The /x lets us break up the regexp with whitespaces and comments
# The /i makes it case insensitive
# The /s makes the . matches newlines.
#
# Two other notes. The .*? construct is a nongreedy match. It matches
# as few as possible. So the regexp "(.*?)" will match a quote
# followed by any character up until the nearest quote. The parentheses
# will capture the matched characters and place them in one of the
# special variables $1, $2 etc.
#
while($text =~ /<a (?# Find the first part of the anchor tag,
followed by..)
\s+href (?# 1 or more whitespaces and the literal HREF,
followed by..)
\s*=\s* (?# an equal sign with optional whitespaces on each
side)
"(.*?)" (?# followed by quote, and capturing anything up to
2nd quote)
.*?> (?# followed by anything up to nearest >)
(.*?)< (?# and finally capturing anything up to nearest <)
/gxsi) {
$url = $1;
$name = $2;
print "$url => $name\n";
}
__END__
Hope this helps
/Fredrik
------------------------------
Date: 18 Jun 1997 08:12:39 GMT
From: jarausch@numa1.igpm.rwth-aachen.de (Helmut Jarausch)
To: topaz56@one.net
Subject: Re: Sorry another regex question - parsing HTML anchors??? Interesting though...
Message-Id: <5o859n$dc8$1@news.rwth-aachen.de>
In article <33a73efa.128472207@news.mindspring.com>, topaz56@one.net writes:
|>
|> I can't figure this out, even after reading (sporadically) through
|> understading regular expressions. What operator matches
|> anything akin to * in unix? Is it *? or (*) or .*? What I'm trying
|> to do is to take input ($data below) & simply parse out the HTML
|> anchor, plus the intervening text, ie...
|>
|> <a href="http://company.com">Company</a>
|>
|> I'd like to dump the url and the name into separate variables, and to
|> add a bit of interest to this, I'd like it to smoothly handle text
|> files generated from Netscape bookmarks. The rough anchors look like
|> this:
|>
|> <DT><A HREF="http://www.web-master.com/forums/career.html"
|> ADD_DATE="855631541" LAST_VISIT="863620321"
|> LAST_MODIFIED="855631523">The Professional Webmaster</A>
|>
|> <DT><A HREF="http://www.w3.org/pub/WWW/Journal/"
|> ADD_DATE="861305717" LAST_VISIT="863622870"
|> LAST_MODIFIED="861305705">World Wide Web Journal</A>
|>
|> I need to remove from ADD_DATE --->LAST_MODIFIED##########"
|>
|> My logic (& it is probably flawed) is to input this data as a scalar &
|> store the variables &url & name in a hash. Am I thinking about this
|> correctly??? And how can I fix the regex below???
|>
|> open (DATAFILE, "$data") || die "Can't open $data\n"; # Open
|> filehandle or die
|>
|> Thanks, Tom
|>
|>
|> while (<DATAFILE>) { # this implicitly loads $_
|> ($url,$name) = ($anchor =~ s/<a href=([^"*"])*>[*]<\[Aa]>/$1 $2/gi);
|>
First, it's not clear whether you expect your data on a SINGLE line or not.
Case I) whole anchor on a single line
use strict;
my ($url,$name);
while(<DATA>)
{ if ( m|<A HREF="([^"]*)"[^>]*>([^>]*)</A>|ig )
{ $url= $1; $name= $2; print "$url $name \n"; }
else { next };
}
__DATA__
<DT><A HREF="http://www.web-master.com/forums/career.html" ADD_DATE="855631541" LAST_VISIT="863620321" LAST_MODIFIED="855631523">The Professional Webmaster</A>
<DT><A HREF="http://www.w3.org/pub/WWW/Journal/" ADD_DATE="861305717" LAST_VISIT="863622870" LAST_MODIFIED="861305705">World Wide Web Journal</A>
Case II) distributed on several lines
use strict;
my ($url,$name);
undef $/; # no input line separator
my $Data = <DATA>; # whole file as a single string
while( $Data =~ m|<A HREF="([^"]*)"[^>]*>([^>]*)</A>|igs )
{ $url= $1; $name= $2; print "$url $name \n"; }
__DATA__
<DT><A HREF="http://www.web-master.com/forums/career.html"
ADD_DATE="855631541" LAST_VISIT="863620321"
LAST_MODIFIED="855631523">The Professional Webmaster</A>
<DT><A HREF="http://www.w3.org/pub/WWW/Journal/"
ADD_DATE="861305717" LAST_VISIT="863622870"
LAST_MODIFIED="861305705">World Wide Web Journal</A>
--
Helmut Jarausch
Lehrstuhl f. Numerische Mathematik
Institute of Technology
RWTH Aachen
D 52056 Aachen, Germany
------------------------------
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 628
*************************************