[13634] in Perl-Users-Digest
Perl-Users Digest, Issue: 1044 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 11 19:05:37 1999
Date: Mon, 11 Oct 1999 16:05:14 -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: <939683113-v9-i1044@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 11 Oct 1999 Volume: 9 Number: 1044
Today's topics:
Re: Advanced text substitution in FILEHANDLES (Larry Rosler)
Re: Case Question. (Tad McClellan)
Re: Case Question. (Larry Rosler)
Re: Case Question. (Craig Berry)
CGI Form interaction question <tralridr@kc.net>
Re: CGI Form interaction question <trailness@hotmail.com>
Re: CGI Form interaction question <ff@arraycomm.com>
Re: CGI Form interaction question <camerond@mail.uca.edu>
Re: Debugging 'segmentation fault' errors (Ilya Zakharevich)
help re perl scripts to submit urls to engines (Roger Jacques)
Help with Garbage Collection. <hart@rohan.sdsu.edu>
Re: Help with Garbage Collection. (Ilya Zakharevich)
Re: Help with Garbage Collection. <ff@arraycomm.com>
how to run an inherited method in your own namespace <ff@arraycomm.com>
Re: how to run an inherited method in your own namespac (Damian Conway)
Re: IIS, Perl and writing <jtolley@bellatlantic.net>
Java perl Lingo <nthailey@geek.com>
Re: lookbehind capabilities was [Re: Help - Perl regula <uri@sysarch.com>
Re: lookbehind capabilities was [Re: Help - Perl regula (Ilya Zakharevich)
Re: Modifying subroutine arguments (Clinton Pierce)
Re: Modifying subroutine arguments (Tad McClellan)
Re: parenthesizing arguments to grep - BLOCK form (Larry Rosler)
Re: Passing unknown filenames as arguments to another p (Alan Barclay)
Re: Passing unknown filenames as arguments to another p <uri@sysarch.com>
Re: returning the first key and value pairing form a so <ff@arraycomm.com>
sendmail/globals? <pribis@trainersdirect.com>
Socket Error <shawn@megadeth.org>
Re: sprintf help <ff@arraycomm.com>
tmtowtdt? Getting the date schablone@my-deja.com
Re: tmtowtdt? Getting the date (Craig Berry)
use strict <frankhale@trespass.net>
Re: use strict (Greg Bacon)
Re: VERY Newbie with stoopid Question <jeff@vpservices.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 11 Oct 1999 14:01:01 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Advanced text substitution in FILEHANDLES
Message-Id: <MPG.126befe925bd9f8398a076@nntp.hpl.hp.com>
In article <r8rM3.3901$nU4.20023@news1.online.no> on Mon, 11 Oct 1999
21:46:51 +0100, Rasmus Rimestad <rasmusr@online.no> says...
...
> open(FILEHANDLE,"sample.txt");
Kragen already commented on this.
> @before = <FILEHANDLE>;
> close(FILEHANDLE);
> foreach $line (@before) {
There is no advantage in copying all of the input into an array. It can
(and should) be processed line-by-line.
> if($line ne "Above name is not in group\n") {
> @after[$i] = $oldName;
> $i++;
Three things wrong here:
You are assigning a scalar to an array slice. You should be
assigning to a scalar ($after[$i]). The '-w' flag would warn you about
this.
You are indexing into an array, when push() would be easier.
There is no advantage in saving all of the output in an array. It
can (and should) be printed line-by-line.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 11 Oct 1999 11:15:12 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Case Question.
Message-Id: <0uust7.qft.ln@magna.metronet.com>
Kevin McCluskey (kevinm@papillonres.com) wrote:
: I am trying to check a variable against an array of keywords and cannot
: get it to ignore the case.
: This is what I have:
: $kw_len = @keywords;
: sub keytest {
: for($i=0;$i<$kw_len;$i++)
^^^^^^
Ack!
Please tell us that you aren't really using a global variable!
You should pass arguments to functions, rather than attempt
the fragile method of using global variables.
You don't need it anyway:
foreach my $i ( 0..$%#keywords )
: {
: if ($word eq $keywords[$i]){
: return 1;}
return 1 if $word =~ /^\Q$keywords[$i]\E$/i; #UNTESTED
Uhhh.
You don't even need an explicit index either...
foreach my $keyword (@keywords) {
return 1 if $word =~ /^\Q$keyword\E$/i; #UNTESTED
}
: If I do: $word eq /$keywords[$i]/i
: I don't get a compare.
What documentation did you see that said you could do that?
: Any ideas ? is it that the "eq" operator does not work right with /i ?
What gave you the idea that /i and "eq" are related somehow?
They are not.
One of them is an operator (eq).
One of them is an option on another operator ( m// )
Read perlop.pod to find out about operators *before* asking
questions about operators!
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 11 Oct 1999 14:35:25 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Case Question.
Message-Id: <MPG.126bf7fbd40665e998a078@nntp.hpl.hp.com>
In article <s04i6nrjh1s76@corp.supernews.com> on Mon, 11 Oct 1999
20:30:15 GMT, Craig Berry <cberry@cinenet.net> says...
> Larry Rosler (lr@hpl.hp.com) wrote:
...
> : It would be more efficient to one-case @keywords once before using it,
> : then replace 'lc' by '$_' in the subroutine.
> :
> : $_ = lc for @keywords;
>
> Would that be more efficient? Pre-lc'ing requires that all keys be
> lowercased; the early-exit loop requires on average half of them.
>
> This argument goes away if you lc @keywords once outside the subroutine
> (and the keyword list is fixed), of course.
That is what I meant (and what I thought I said -- see the word 'once'
in the sentence quoted above).
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 11 Oct 1999 22:16:35 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Case Question.
Message-Id: <s04oe3i2h1s30@corp.supernews.com>
Larry Rosler (lr@hpl.hp.com) wrote:
: > This argument goes away if you lc @keywords once outside the subroutine
: > (and the keyword list is fixed), of course.
:
: That is what I meant (and what I thought I said -- see the word 'once'
: in the sentence quoted above).
The ambiguity was whether your 'once' was subroutine-block-scope or
program-scope. :) Thanks for the confirming clarification.
--
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| "There it is; take it." - William Mulholland
------------------------------
Date: Mon, 11 Oct 1999 16:35:57 -0500
From: Trail-Rider <tralridr@kc.net>
Subject: CGI Form interaction question
Message-Id: <3802583D.6FED62E6@hotmail.com>
I'm a newbie to Perl (all right, stop the snickers and groans) and am
having difficulty getting a program to work. I've made an order form for
web design; my program is supposed to use input values to generate a new
html page for the viewer, giving them an estimate of cost, and send an
e-mail to me letting me know what they want so I can give a firmer
price.
I have checked to be sure the file permissions are set right, and my
server does support CGI programming with Perl because I have several
basic scripts that work just fine. There must be some sort of little
mistake that I am not catching. I'd like to find out what's wrong, why,
and how to fix it- and if you have any suggestions as to improving
anything, they're welcome. Please send a private e-mail to me; don't
just reply to this in the newsgroup, as I don't have much time on my
hands and it will take less time to check mail than it would to check
the group. Thanks very much.
I've tried looking through my _Teach Yourself CGI Programming with Perl
5 in a Week_ and famed llama books, but I haven't been able to determine
how to get an e-mail to include what I want how I want it. I just want
to include all the input, separated by lines and labeled by my specified
categories, so that I can work with the data. I'm just unsure of the
syntax.
So in essence, this little program needs to be debugged (I get an
"internal server error" message when I submit the form; I'm sure it's
just a small newbie error) and needs to have e-mail output specified.
The program, cost2.cgi:
#!/usr/local/bin/perl
push(@INC, "/cgi-bin");
require("cgi-lib.pl");
&ReadParse(*input);
#determine base price
if ($input{'typeofpage'} eq "Standard") {
#set Standard variables
$typeofpage = "Standard";
$price = 75;
$price2 = 75;
}
elsif ($input{'typeofpage'} eq "StandardWWW") {
#set StandardWWW variables
$typeofpage = "Standard Plus";
$price = 150;
$price2 = 150;
}
elsif ($input{'typeofpage'} eq "Enhanced") {
#set Enhanced variables
$typeofpage = "Enhanced";
$price = 75;
$price2 = 75;
}
else {
#must be EnhancedWWW
$typeofpage = "Enhanced Plus";
$price = 150;
$price2 = 150;
}
#add extra price if extra options are selected
if (defined($input{'CreateLogo'})) {
$price += 10;
$price2 += 30;
}
if (defined($input{'CreateGraphics'})) {
$price += 10;
$price2 += 50;
}
if (defined($input{'Scanning'})) {
$price += 5;
$price2 += 20;
}
if (defined{$input{'Subpages'})) {
$price += 5;
$price2 += 20;
}
if (defined{$input{'Typing'})) {
$price += 5;
$price2 += 20;
}
if (defined{$input{'Catalog'})) {
$price += 10;
$price2 += 20;
}
if (defined{$input{'OrderForm'})) {
$price += 20;
$price2 += 50;
}
if (defined{$input{'Counter'})) {
$price += 10;
$price2 += 10;
}
if (defined{$input{'Frame'})) {
$price += 5;
$price2 += 20;
}
if (defined{$input{'Bkgnd'})) {
$price += 10;
$price2 += 30;
}
if (defined{$input{'AniGIF'})) {
$price += 10;
$price2 += 40;
}
if (defined{$input{'Table'})) {
$price += 5;
$price2 += 30;
}
if (defined{$input{'Sitemap'})) {
$price += 5;
$price2 += 20;
}
if (defined{$input{'Feedback'})) {
$price += 10;
$price2 += 20;
}
print &PrintHeader;
print<<"print_tag";
<html>
<head>
<title>$typeofpage Page from Blue Moon Designs</title>
</head>
<body bgcolor=111199 text=ffffff link=bbbbbb alink=777777 vlink=777777>
<center><font face="arial,geneva" size=4>Thank you for choosing Blue
Moon Designs! A website with the options you have chosen
will cost approximately $price to $price2. You will receive e-mail
confirmation and a firmer price within 3 business days of
form submission.</center><br>
<center><a href="/bluemoon/index.html" target="_top">Return</a> to the
Blue Moon Designs homepage</center>
<br>
</body>
</html>
print_tag;
open Mail,"|mail tralridr@worldnet.att.net";
print MAIL "i want to add the form input here\n;
close mail;
The form itself is at
http://trailrider.virtualave.net/bluemoon/forder.html if you'd like to
see it.
Thanks so much for your help!
Elaine Binns (TheCat)
trailness@hotmail.com
------------------------------
Date: Mon, 11 Oct 1999 16:43:22 -0500
From: TheCat <trailness@hotmail.com>
Subject: Re: CGI Form interaction question
Message-Id: <380259FA.D19E5CB1@hotmail.com>
Terribly sorry about this, but here's your chance to laugh at the
newbie. My current e-mail address is trialness@hotmail.com- please don't
use the tralridr@kc.net or trail-rider@geocities.com accounts.
Sorry again. :(
Elaine Binns
------------------------------
Date: Mon, 11 Oct 1999 22:14:32 GMT
From: Farhad Farzaneh <ff@arraycomm.com>
Subject: Re: CGI Form interaction question
Message-Id: <38026148.43A40C17@arraycomm.com>
WRT your last question:
Look in the apache error_log file (or other log file for other web
servers) to see what the error is.
You can also try to run the script from the command line to see if it's
just a syntax error.
--Farhad
TheCat wrote:
>
> Terribly sorry about this, but here's your chance to laugh at the
> newbie. My current e-mail address is trialness@hotmail.com- please don't
> use the tralridr@kc.net or trail-rider@geocities.com accounts.
>
> Sorry again. :(
> Elaine Binns
--
Farhad
------------------------------
Date: Mon, 11 Oct 1999 17:42:35 -0500
From: Cameron Dorey <camerond@mail.uca.edu>
Subject: Re: CGI Form interaction question
Message-Id: <380267DB.52EE5262@mail.uca.edu>
[not cc'd to eb]
TheCat wrote:
>
> [snipped]
I see from your headers that you are using Window$. I have three pieces
of general advice:
1. Burn the "Teach yourself..." book (I burned mine, it made a good
firestarter for a campfire), unfortunately you would have been better
off with the gecko (LP on Win32 Systems) than the llama, but unless you
can get somebody to buy this off you, it probably isn't worth the
trouble.
2. Dump cgi-lib.pl, it's ancient and hard to get everything right (at
least for me), use CGI.pm, it comes with core Perl, and is infinitely
easier to use (you might want to get "The Official Guide to Programming
with CGI.pm" for a lot of tutoring in it, but the docs are quite good in
themselves).
3. Use Mail::Sendmail or Mail::Sender to send your mail with. They are
both very easy to use.
Oh, and 4. Don't ever use a lame excuse like "I don't have much time on
my hands and it will take less time to check mail than it would to check
the group" to get somebody to email you a response. I really thought
thrice before I did, and I bet nobody else will, because this is the
essence of "well, i can't be bothered with making it easy for somebody
to give me free help, i'm worth more than them." Hmm, make it four
times, "Use the group, view the group." If you don't see this, it's your
loss, sorry.
Cameron
--
Cameron Dorey
Associate Professor of Chemistry
University of Central Arkansas
Phone: 501-450-5938
camerond@mail.uca.edu
------------------------------
Date: 11 Oct 1999 22:07:01 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Debugging 'segmentation fault' errors
Message-Id: <7ttn25$95l$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to
<jboes@my-deja.com>],
who wrote in article <7tti4g$ebm$1@nnrp1.deja.com>:
> How does one go about trying to figure out 'segmentation fault' errors
> from a Perl script? The script isn't doing anything in particular; at
> the point of the error it appears to be executing
>
> return 0;
>
> from a subroutine in a package back to my main program.
This "should not happen". Which means that the memory of the process
is screwed up by some XS or other buggy code.
In turn, it means that debugging it is hard. Judging by the fact that
you are asking ;-), I would not want to go into details. :-(
Well, here is the hint: make sure you know how a correct layout of
things in memory looks like. Find a contradiction at the time of
segfault. Set watchpoints on the suspicious data and restart. Find
who writes them (the last time!).
Most probably it will not stop here. "Who writes them" is usually
LEAVE (which restores values of saved=localized variables etc). So
you need to set watchpoints on the positions in the "savestack", to
find out who requested this operations during LEAVE. Then you may
need to find out why this "who" is behaving like this. You find what
is the normal layout of data for "who", and what contradicts it. Then
the process repeats.
The situation is very much complicated by absense of hardware
watchpoints in your debugger. It is also hard to find *the last
modification* without help from your debugger (say, gdb count
breakpoint hits, and allows you to postpone until the nth hit).
And: you may want to insert some meaningless rare
opcode near the suspicious point (such as binmode(STDERR)) and set a
breakpoint in Perl_pp_binmode(). Disable your watchpoints and run
from start until this point. Check that the memory layout is OK
at this point, and enable your watchpoints only for the rest of the
run (which is supposedly not so long).
Ilya
------------------------------
Date: 11 Oct 1999 20:53:50 GMT
From: channel@sunsite.unc.edu (Roger Jacques)
Subject: help re perl scripts to submit urls to engines
Message-Id: <7ttiou$8b7$1@fddinewz.oit.unc.edu>
I have recently taken on a contract for a project
that involves using Perl to write scripts that will
make URL submissions to hundreds of search engines.
I know there is a lot of this gong on now and I need
help getting started. I am fairly experienced with
Perl and have used to extract pages from the
Internet on a periodic basis but have not yet used
Perl scripts to write to online forms.
I need instructions and directions to available
scripts that I could use as an examples ... anything
that might help me get started. I intend to use
mod-perl since we have an Apache server.
Please reply to -- channel@metalab.unc.edu, as
well as to this posting.
Thank you in advance for your help.
...roger
------------------------------
Date: Mon, 11 Oct 1999 14:58:47 -0700
From: George hart <hart@rohan.sdsu.edu>
Subject: Help with Garbage Collection.
Message-Id: <38025D96.2848FA05@rohan.sdsu.edu>
Hi,
I have a program that deals with some large variables. I am concerned
that they will hog up memory. A simplified version of my program is:
$x = &data1;
$x = &data2;
Since I redeclare $x a second time, can I assume that the
information returned from sub data1 has been disposed of? If not, is
there anyway to force garbage collection?
One other question, is there any way to see how perl handles memory
during runtime?
Thank you for your time,
George Hart
hart@rohan.sdsu.edu
San Diego
------------------------------
Date: 11 Oct 1999 22:09:36 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Help with Garbage Collection.
Message-Id: <7ttn70$962$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to George hart
<hart@rohan.sdsu.edu>],
who wrote in article <38025D96.2848FA05@rohan.sdsu.edu>:
> I have a program that deals with some large variables. I am concerned
> that they will hog up memory. A simplified version of my program is:
> $x = &data1;
> $x = &data2;
> Since I redeclare $x a second time
You declared $x exactly 0 times.
> , can I assume that the
> information returned from sub data1 has been disposed of?
No.
> If not, is
> there anyway to force garbage collection?
There is no garbage collection in Perl. But undef $x should detach all
the memory buffers from $x.
> One other question, is there any way to see how perl handles memory
> during runtime?
perldoc perldebug
Ilya
------------------------------
Date: Mon, 11 Oct 1999 22:17:04 GMT
From: Farhad Farzaneh <ff@arraycomm.com>
To: George hart <hart@rohan.sdsu.edu>
Subject: Re: Help with Garbage Collection.
Message-Id: <380261E0.5B1C7DA1@arraycomm.com>
Perl should perform automatic garbage collection and free up the memory
if no other variable is referencing it. I imagine that you can use gdb
or other debugger to see the memory actually free up but I don't know
how to do that. Sorry.
--Farhad
George hart wrote:
>
> Hi,
>
> I have a program that deals with some large variables. I am concerned
> that they will hog up memory. A simplified version of my program is:
>
> $x = &data1;
>
> $x = &data2;
>
> Since I redeclare $x a second time, can I assume that the
> information returned from sub data1 has been disposed of? If not, is
> there anyway to force garbage collection?
>
> One other question, is there any way to see how perl handles memory
> during runtime?
>
> Thank you for your time,
>
> George Hart
> hart@rohan.sdsu.edu
> San Diego
--
Farhad
------------------------------
Date: Mon, 11 Oct 1999 21:21:06 GMT
From: Farhad Farzaneh <ff@arraycomm.com>
Subject: how to run an inherited method in your own namespace
Message-Id: <380254C2.7346BDFF@arraycomm.com>
When an object module's method is called, if perl can't find the method
in the current module, it looks at the parent's symbol table to see if
the method is defined there. However, it looks like the function runs
from the parent's symbol table, not the child's, so any symbols defined
in the child's symbol space are not understood by the function. Here is
an example:
package car;
sub new {
my $pkg = shift;
my $self = {};
bless $self, $pkg;
$self;
}
sub build {
eval("headlights()");
if ( $@ ) {
print "Eval error!! : $@ \n";
}
return;
}
1;
-----------------
package volvo;
use strict;
use Exporter;
use car;
use vars qw(@ISA);
@ISA = qw(car);
sub new {
my $pkg = shift;
my $self = $pkg->SUPER::new();
bless $self,$pkg;
$self;
}
sub headlights {
print "Building the car headlights\n";
}
1;
-------------------
#!/bin/perl -w
use strict;
use volvo;
my $c = new volvo;
$c->build();
When the script runs I get the error
Eval error!! : Undefined subroutine &car::headlights called at (eval 1)
line 1.
Is there a way to run this function in the inheritor's namespace?
Thanks
--
Farhad
------------------------------
Date: 11 Oct 1999 22:45:13 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: how to run an inherited method in your own namespace
Message-Id: <7ttp9p$797$1@towncrier.cc.monash.edu.au>
Farhad Farzaneh <ff@arraycomm.com> writes:
>When an object module's method is called, if perl can't find the method
>in the current module, it looks at the parent's symbol table to see if
>the method is defined there. However, it looks like the function runs
>from the parent's symbol table, not the child's, so any symbols defined
>in the child's symbol space are not understood by the function.
Only if you call it as a subroutine, rather than a method (as you do in
the eval. What you need is:
sub build {
$_[0]->headlights;
if ( $@ ) {
print "Eval error!! : $@ \n";
}
return;
}
or possibly:
sub build {
eval { $_[0]->headlights };
if ( $@ ) {
print "Eval error!! : $@ \n";
}
return;
}
if you needed the eval for some purpose other than debugging.
Damian
------------------------------
Date: Mon, 11 Oct 1999 22:27:15 GMT
From: James Tolley <jtolley@bellatlantic.net>
Subject: Re: IIS, Perl and writing
Message-Id: <380263B0.F61C9A27@bellatlantic.net>
A code snippet, please? It might be as simple as "+>$filename" in place of
"$filename", but there's no way to know without seeing the offending code.
------------------------------
Date: Mon, 11 Oct 1999 17:47:44 -0500
From: Nick Hailey <nthailey@geek.com>
Subject: Java perl Lingo
Message-Id: <38026910.77C5E505@geek.com>
Has anyone had any experience using Java Perl Lingo (JPL) , the toolkit
for creating Java-Perl applications?...supposedly it allows you to
invoke Perl from Java as well as call Java from Perl. I've seen links
on the O'reilly site that talks about it but I've not been able to find
anything of substance.
------------------------------
Date: 11 Oct 1999 17:18:16 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: lookbehind capabilities was [Re: Help - Perl regular expression question!]
Message-Id: <x74sfxmw9z.fsf@home.sysarch.com>
>>>>> "IZ" == Ilya Zakharevich <ilya@math.ohio-state.edu> writes:
IZ> Emacs can do it. I do not remember anyone shooting himself with
IZ> re-backward-search.
>>
>> that is not a backwards regex. it is a backwards moving search that uses
>> a forward matching regex. same as search-backwards also compares
>> forwards as it move backwards through the buffer.
IZ> How do you know? This is an implementation detail.
i can't know for sure but in some browsing the code emacs just seems to
do a plain regex match on a spot. so it is matching the text
forward. then it will increment/decrement the spot according to the
direction. it never says it does a true reverse regex match. i don't
think their regex engine could do that.
>> but i am intrigued by the /r modifier. any work being done on it?
IZ> It is absolutely trivial to do (as in: to match "cde", first try to
IZ> move 3 units backwards, to match [cde], first move one unit backwards,
IZ> etc). What scares me is the series of benchmarking to find whether
IZ> having additional-branches/additional-checks would actually slow down
IZ> things noticably.
this is matching forward but moving backwards on failures. i was
thinking about actually regex matching the string backwards as in:
'abcdef' =~ /fed/r
would be true.
this is more like doing a reverse on the data and applying the regex.
IZ> [Of course, I assume that for the first implementation one would need
IZ> to *write* your REx backwards ;-). Then an auto-inverter should be
IZ> written, but this is pretty easy.]
or reverse the string before matching. whichever is shorter/quicker.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
www.sysarch.com ----- Perl Books: http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: 11 Oct 1999 21:54:49 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: lookbehind capabilities was [Re: Help - Perl regular expression question!]
Message-Id: <7ttmb9$91h$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Uri Guttman
<uri@sysarch.com>],
who wrote in article <x74sfxmw9z.fsf@home.sysarch.com>:
> >> that is not a backwards regex. it is a backwards moving search that uses
> >> a forward matching regex. same as search-backwards also compares
> >> forwards as it move backwards through the buffer.
>
> IZ> How do you know? This is an implementation detail.
>
> i can't know for sure but in some browsing the code emacs just seems to
> do a plain regex match on a spot. so it is matching the text
> forward. then it will increment/decrement the spot according to the
> direction. it never says it does a true reverse regex match. i don't
> think their regex engine could do that.
Of course it cannot do it! But the substitution the engine uses is
good enough, so the user will not know.
> this is matching forward but moving backwards on failures.
I would say moving backwards on/before success. ;-)
> i was
> thinking about actually regex matching the string backwards as in:
>
> 'abcdef' =~ /fed/r
>
> would be true.
As I said, the initial implementation will look like this, but this
will be a temporary limitation only. For me "Backward match" means
"Trace" both the string and the REx from tail to start.
Ilya
------------------------------
Date: Mon, 11 Oct 1999 20:08:20 GMT
From: cpierce1@ford.com (Clinton Pierce)
Subject: Re: Modifying subroutine arguments
Message-Id: <380240c1.529992488@news.ford.com>
[poster cc'd in e-mail]
On Mon, 11 Oct 1999 18:02:50 GMT, rwentwor@advent.com wrote:
>I'm trying to pass two variables to a subroutine and modify the values.
That's simple, straightforward and not hard to do.
>Here's the subroutine:
>sub GetCheckoutInfo {
> my $Filename = shift;
> local *User = \$_[0];
> local *Dir = \$_[1];
> my $Line;
Wow. That's just AWFUL.
> GetCheckoutInfo("status.lst", $Username, $Path);
Ok, there's a few ways to go about this. Starting off, in a subroutine,
you can modify the elements of @_ directly and affect the caller's
variables. For example, if you had said:
$_[1]="Foo";
$Username would get set to "Foo" in the caller. This method tends to
obfuscate what's really going on though.
The more straightforward way to do this is like this:
sub GetCheckoutInfo {
my($Filename, $COI_user, $COI_path)=@_;
$$COI_user="Foo"; # Changes the value of $Username in the caller
$$COI_path="junk"; # " " " " $Path " " "
And then call it by:
GetCheckoutInfo("status.lst", \$Username, \$Path);
Using local() is mostly a Perl 4-ism; you'll probably never have a good
reason to use it in Perl 5. Same can be said for globs. "use strict" was
complaining justly. Use "my", pass references, and avoid globs unless you
really know what you're doing.
--
Clinton A. Pierce "If you rush a Miracle Man, you get rotten
clintp@geeksalad.org Miracles." -- Miracle Max, The Princess Bride
http://www.geeksalad.org
------------------------------
Date: Mon, 11 Oct 1999 13:47:36 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Modifying subroutine arguments
Message-Id: <or7tt7.blt.ln@magna.metronet.com>
rwentwor@advent.com wrote:
: I've tried getting an answer from the various man pages but nothing
: worked properly. I also did a search through the old newsgroup postings
: without any luck.
You are a good Usenet citizen.
A comparative rarity in these parts...
: Perhaps I'm missing something obvious?
You want to be both non-strict and strict simultaneously,
something's got to give.
( I recommend giving up on non-strictness :-)
: I'm trying to pass two variables to a subroutine and modify the values.
: Here's the subroutine:
: sub GetCheckoutInfo {
: my $Filename = shift;
: local *User = \$_[0];
: local *Dir = \$_[1];
Those last 2 are package global variables.
"use strict" disallows that, unless you also have them in a "use vars".
[snip]
: $User = substr($Line,20,8);
: $Dir = substr($Line, 56);
: The above subroutine works as long as I DON'T include "use strict;".
Yes, because you are using package global variables without "use vars".
"use strict" is _supposed_ to kick you out for trying that.
: Perl kicks out:
[snip error messages]
: I prefer to keep the extra safeties turned on.
Me too, but then don't try to do non-strict things :-)
: I was finally able to
: get it working by deleting the two "local" lines and replacing the last
: two lines with:
: $_[0] = substr($Line,20,8);
: $_[1] = substr($Line, 56);
: I can live with this solution for this short subroutine. However, it
: still annoys me that I can't figure out how to do this in the "proper"
: fashion.
Your first attempt can do it in the (somewhat) "proper" fashion
if you add:
use vars qw( $User $Dir);
But global variables are something that should be avoided.
: I feel this will become important in a more complicated
: subroutine when using "$_[?]" would be too cryptic.
When the code becomes "more complicated", you want strictness
even more.
: Could someone please enlighten me as to the proper way to work with
: variables by reference. Thanks.
Here is (IMO) the best way: use regular references instead of
a symbol table glob.
my $User = \$_[0];
my $Dir = \$_[1];
^^ ^
^^ ^
$$User = substr($Line,20,8);
$$Dir = substr($Line, 56);
^^
^^
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 11 Oct 1999 14:21:34 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: parenthesizing arguments to grep - BLOCK form
Message-Id: <MPG.126bf4b87def230898a077@nntp.hpl.hp.com>
In article <7ttg0k$cq9$1@nnrp1.deja.com> on Mon, 11 Oct 1999 20:06:56
GMT, jrw32982@my-deja.com <jrw32982@my-deja.com> says...
> In article <MPG.126bcd4c9bbeec5f98a070@nntp.hpl.hp.com>,
> lr@hpl.hp.com (Larry Rosler) wrote:
> > grep(BLOCK, ...)
> >
> > > BTW, what do you call those thingies and what exactly is their
> > > syntactic
> > > status.
> >
> > See above.
>
> I meant the thingies which don't require/allow a comma after them.
> Other arguments are collected into a list, but these weird thingies
> apparently can't be collected into the argument list (at least for
> print() they can't) but instead need to be distinguished
> syntactically. If they don't need to be distinguished syntactically,
> then there would be no need for error messages like "No comma allowed
> after filehandle".
What I wrote above should not have had the comma. The syntax is
grep BLOCK LIST
grep EXPR, LIST
perldoc -f grep
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 11 Oct 1999 21:34:31 GMT
From: gorilla@elaine.drink.com (Alan Barclay)
Subject: Re: Passing unknown filenames as arguments to another program
Message-Id: <939677976.180174@elaine.drink.com>
In article <slrn804ad7.gep.abigail@alexandra.delanet.com>,
Abigail <abigail@delanet.com> wrote:
>Randal L. Schwartz (merlyn@stonehenge.com) wrote on MMCCXXXII September
>MCMXCIII in <URL:news:m1r9j1zwvx.fsf@halfdome.holdit.com>:
>** >>>>> "Abigail" == Abigail <abigail@delanet.com> writes:
>**
>** Abigail> Assuming blastcl3 can take multiple arguments:
>**
>** Abigail> ls *.seq | xargs blastcl3
>**
>** Fails if any *.seq are directories. Nearly useless use of ls there.
>**
>** blastcl3 *.seq
>**
>** would be closer.
>
>
>Nope. He said "hundreds of files". Which would mean `blastcl3 *.seq'
>might very well run into shell buffer limits. That's why I used the xargs.
Wouldn't `ls *.seq` have the same problem?
`find . -name '*.seq' -maxdepth 1` doesn't, because it's using find's
internal globber.
`find . -name '*.seq' -type f -maxdepth 1` passes both tests.
------------------------------
Date: 11 Oct 1999 18:28:09 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Passing unknown filenames as arguments to another program
Message-Id: <x7n1tpleh2.fsf@home.sysarch.com>
>>>>> "A" == Abigail <abigail@delanet.com> writes:
A> Randal L. Schwartz (merlyn@stonehenge.com) wrote on MMCCXXXII September
A> MCMXCIII in <URL:news:m1r9j1zwvx.fsf@halfdome.holdit.com>:
A> ** >>>>> "Abigail" == Abigail <abigail@delanet.com> writes:
A> **
A> ** Abigail> ls *.seq | xargs blastcl3
A> **
A> ** Fails if any *.seq are directories. Nearly useless use of ls there.
A> **
A> ** blastcl3 *.seq
A> **
A> Nope. He said "hundreds of files". Which would mean `blastcl3 *.seq'
A> might very well run into shell buffer limits. That's why I used the xargs.
randal's point about ls and dirs is valid. so you use echo *.seq
instead. xargs is needed if the number of files will blow up the shell's
line buffer or max command line args.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
www.sysarch.com ----- Perl Books: http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Mon, 11 Oct 1999 21:32:13 GMT
From: Farhad Farzaneh <ff@arraycomm.com>
Subject: Re: returning the first key and value pairing form a sorted hash
Message-Id: <3802575D.8F2819C5@arraycomm.com>
Are you crerating an error histogram??
Hashes are intrinsically unordered so there is no real concept of the
"first" element of a hash.
You can use the module Tie::IxHash to get a sorted hash or you can
create your own.
Now if you just want to print the first point corresponding to the
lowest error:
$errorList{(sort keys %errorList)[0]}[0];
ought to do it, although I haven't tested it.
if you don't care about the order, how about
while ( my($k,$v) = each %errorList ) {
print "$k, $v->[0]\n";
}
Tom Kralidis wrote:
>
> Hi,
>
> I've generated a hash from various array elements, with:
>
> foreach (@array)
> {
> @line = split (/\s+/, $_);
> print "x,y fits: $line[5], $line[6]\n";
> $pointID = $line[1];
> $error = (abs $line[5]) + (abs $line[6]);
> printf "Total error of $pointID is: %.3f metres \n", $error;
> push(@{ $errorList{$error} }, $pointID );
> }
>
> # then printing the hash out
>
> print "Error ID\n\n";
> foreach $string (reverse sort keys %errorList)
> {
> print "$string: @{$errorList{$string}}\n";
> }
>
> ..from this sorted list, I would like to assign the first key and value
> pairing to an array, to use in other files, but can't seem to make it
> happen. I can't seem to find the correct syntax.
>
> I tried printing:
>
> print "$errorList[0][0]\n";
>
> ..but got an uninitialized value.
>
> Can anyone offer some advice?
>
> Thanks
>
>
> -----------------------------------------------------------------------------------------
> Tom Kralidis Geo-Spatial Technologist
> Canada Centre for Remote Sensing Tel: (613) 947-1828
> 588 Booth Street , Room 241 Fax: (613) 947-1408
> Ottawa , Ontario K1A 0Y7 http://www.ccrs.nrcan.gc.ca
> -----------------------------------------------------------------------------------------
--
Farhad
------------------------------
Date: Sat, 9 Oct 1999 11:59:38 -0400
From: "Brian Pribis" <pribis@trainersdirect.com>
Subject: sendmail/globals?
Message-Id: <37ff86aa@news.together.net>
I wrote a script using a MailTools mod. Basically (in a vary large nut
shell) it uses sendmail to email a HTML formatted letter to a rather large
mailing list. I do this through linux. My problem is this: I get about
100 to 150 bounced back due to bad addresses, server down, server vaporized,
recipient on a safari or whatever. This is held in sendmail's spool and of
course send mail will spend so much time trying to get the mail to send.
When it doesn't I (as root) am notified of this with another email
containing the error, original email, and a rather large header. I want to
be able to, using my bulk mail program, read these into an error log, and
possibly have it pull the bad addresses out of the mail list.
I can do the last part easy enough, it is having perl read this stuff
into a file that I want. Any ideas? As I am writing this I am thinking
that I may just be able to read the spool directly, but I don't know. Any
input would be wonderful.
Thank you.
Brian Pribis.
------------------------------
Date: Mon, 11 Oct 1999 14:24:02 -0700
From: Shawn Ramsey <shawn@megadeth.org>
Subject: Socket Error
Message-Id: <38025572.62CC6C7B@megadeth.org>
I am trying to create a socket connection, and I am getting the
following error :
Software error:
Socket could not be created. Reason: delete,shawn Permission denied
For help, please send mail to the webmaster (webmaster@cpl.net), giving
this error message and the time and date of the error. ;
Basically what we are trying to do is create a page that allow removal
of user accounts. Our script attempts to connect connect to port 9001,
where a server under inetd is running. It works fine with PHP, but can't
get PERL to work. Basically all I am doing to sending the command
'delete' and the name of the user to delete. I'll post the code if
needed, but I didn't write it, so thought id ask. Maybe this is a common
problem, permissions on the file, or whatever...
------------------------------
Date: Mon, 11 Oct 1999 21:24:31 GMT
From: Farhad Farzaneh <ff@arraycomm.com>
To: Scott Beck <scott_beck@my-deja.com>
Subject: Re: sprintf help
Message-Id: <3802558F.FD0C874F@arraycomm.com>
The sprintf command mimics the C sprintf command. You should be able to
find ample documentation on it in C books or online on a unix system:
man sprintf.
#!/bin/perl -w
my $x = sprintf("This is a test: %d\n",22);
print $x;
Scott Beck wrote:
>
> Can someone point in the write direction to learn more
> about the sprintf command. I have read the perldocs on it
> and none of them seem to get into much detail.
>
> --
> Thanks
> Scott Beck
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
--
Farhad
------------------------------
Date: Mon, 11 Oct 1999 21:07:27 GMT
From: schablone@my-deja.com
Subject: tmtowtdt? Getting the date
Message-Id: <7ttji5$fj3$1@nnrp1.deja.com>
In order to proceed with my plans for complete world domination I need
to get the current date in the format "yyyy.mm.dd". This is the way
I have come up with:
#!/usr/bin/perl -w
use strict;
my $Today = ((localtime)[5]+1900)."." .((localtime)[4]+1) ."."
.(localtime)[3];
print $Today."\n";
exit(0);
Are there other ways of doing this? Preferably shorter and/or more
cryptic)?
Yours
Schablonski
currently ranked at 155,324,441 in the Potential World Dictators' League
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 11 Oct 1999 22:31:28 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: tmtowtdt? Getting the date
Message-Id: <s04pa0bth1s61@corp.supernews.com>
schablone@my-deja.com wrote:
: In order to proceed with my plans for complete world domination I need
: to get the current date in the format "yyyy.mm.dd". This is the way
: I have come up with:
:
: #!/usr/bin/perl -w
: use strict;
:
: my $Today = ((localtime)[5]+1900)."." .((localtime)[4]+1) ."."
: .(localtime)[3];
Notice that this won't give you the guarantee of two-place month and day
values that your template above (mm.dd) seems to specify. I'd tend to
write this as
my ($day, $month, $year) = (localtime)[3, 4, 5];
$month++;
$year += 1900;
my $Today = sprintf "$year.%02d.%02d", $month, $day;
This will yield e.g. '1999.07.04' for the 4th of July this year.
: Are there other ways of doing this? Preferably shorter and/or more
: cryptic)?
use POSIX;
my $Today = strftime('%Y.%m.%d', localtime);
Best of luck on the whole world domination thing, by the way. I mean, we
will bury you and all that, but best of luck.
--
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| "There it is; take it." - William Mulholland
------------------------------
Date: Mon, 11 Oct 1999 18:36:47 -0500
From: Frank Hale <frankhale@trespass.net>
Subject: use strict
Message-Id: <3802748F.70F65541@trespass.net>
I am in the process of writing a cgi application. I am relatively new to
perl and would like to know if I should use the "-w" option and "use
strict;" in all my scripts? Is it bad practice to not use these?
--
From: Frank Hale
Email: frankhale@trespass.net
ICQ: 7205161
------------------------------
Date: 11 Oct 1999 22:51:36 GMT
From: gbacon@ruby.itsc.uah.edu (Greg Bacon)
Subject: Re: use strict
Message-Id: <7ttplo$5nf$2@info2.uah.edu>
In article <3802748F.70F65541@trespass.net>,
Frank Hale <frankhale@trespass.net> writes:
: I am in the process of writing a cgi application. I am relatively new to
: perl and would like to know if I should use the "-w" option and "use
: strict;" in all my scripts? Is it bad practice to not use these?
Yes, yes, no, and yes. The only time that I don't enable -w and use
strict is when I'm writing a quick one-off. You should also consider
enabling taint checks (with -T; see man perlsec). I've lost count of
the number of times these have saved my butt.
Greg
--
The magic words are squeamish ossifrage.
------------------------------
Date: 11 Oct 1999 20:47:04 GMT
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: VERY Newbie with stoopid Question
Message-Id: <38024C7E.4625679E@vpservices.com>
blackfrd wrote:
>
> OK, I am a little embarrased to ask this.
>
> But here goes. I have the Perl stable interpreter (?) on my windows NT
> ...
> I write a program in notepad.
>
> Now how the hell do I run it?
Click on the start button, then select programs/activePerl/documentation
and find the answer to your question in the section called "getting
started".
When you post to usenet, please use more informative subject lines. If
you had, maybe the next newbie could just find this answer and not have
to re-ask the question.
--
Jeff
------------------------------
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 1044
**************************************