[11218] in Perl-Users-Digest
Perl-Users Digest, Issue: 4818 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 3 18:17:24 1999
Date: Wed, 3 Feb 99 15:01:28 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 3 Feb 1999 Volume: 8 Number: 4818
Today's topics:
Re: Perl Criticism topmind@technologist.com
Re: Perl Criticism topmind@technologist.com
perl newbie: need help pasing web forms <mnanfito@ups.edu>
Perl Path (FTMOM42)
Re: perl/tk slow dialog mapping?? (fwd) prabhashshrestha@my-dejanews.com
Re: problem forking with perl: child sometimes dies k2k2@my-dejanews.com
Read emails from a perl program dragnovich@my-dejanews.com
Re: Simple Perl Script (Martien Verbruggen)
Re: UNIX 'tail' command in Perl?? <scott.dummer@noaa.gov>
Re: Unlink Symlink <ludlow@us.ibm.com>
Re: Using a variable as a variable name <tripp.lilley@perspex.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 03 Feb 1999 20:59:59 GMT
From: topmind@technologist.com
Subject: Re: Perl Criticism
Message-Id: <79adca$h4$1@nnrp1.dejanews.com>
In article <slrn7bf88q.orc.sholden@pgrad.cs.usyd.edu.au>,
sholden@cs.usyd.edu.au wrote:
> On Tue, 02 Feb 1999 13:47:32 GMT, topmind@technologist.com wrote:
> >In article <slrn7b9ujh.4tu.sholden@pgrad.cs.usyd.edu.au>,
> > sholden@cs.usyd.edu.au wrote:
> >>
> >> Basically, avoid comments. If your code needs a comment to be
> >> understood, it would be better to rewrite it so it's easier to
> >> understand. --Rob Pike
> >>
> >
> >I disagree with that statement. Sometimes one comment
> >will nicely summarize a dozen or so lines of code. Also,
> >by hinting the reader about the code BEFORE they read
> >it helps them figure it out faster. Otherwise, one
> >pass is needed to make a guess, and a second to verify
> >the guess.
>
> Any rule like that is a guideline that should apply most of the time. It is
> not a law or anything.
>
> Notice he said 'needs a comment to be understood' not 'needs a comment to
> be understood in two seconds'.
>
> Rob Pike's comment was meant to be interpreted something along the lines of
> if you find yourself commenting your code because you think others will have
> trouble understanding it, then rewrite it.
>
> >
> >For example, "sort list" takes only two
> >seconds to understand. However, if somebody stumbled upon
> >sorting code without knowing what it does, it would
> >usually take them several minutes to figure out
> >what it is doing. Those two words are a bargain.
>
> That's only true if the author can't write code in a readable fashion.
> I would write sort list like this and it would not need any comments (though I
> do put header comments on functions anyway)...
>
> void
> sort_list(List list)
> {
> /*insert code here*/
> }
>
Not all segments are in subroutines; thus, have no
code place to put a label on them. My pattern is
each subroutine averages about 5 segments that do
something descrete. I usually label the start of
each segment.
A newspaper article is self-documenting, but the
headline helps set the stage. Most business writing
experts claim it is best to provide a summary BOTH
at the beginning and the end. Thus, a "headline"
or pre-summary is good practice in any written setting
(Except perhaps where you want to use drama or
suprise to put a point across.)
> Good code doesn't need simple comments line 'sort list' the function name
should
> provide that level of comment. If you inline soorting code then you are a
> performance freak and I don't want to have to read your code anyway...
>
> In fact the comment I would have would be something along the lines of
>
> /* sort_list is an implementation of the algorithm described in Blah on
> pages blah-blah by Bill Blah...*/
>
> >
> >Further, if there is a bug, then reading only the code
> >may not indicate what was INTENDED. Only comments can
> >tell what was intended.
>
> In which case the refernce to literature will be of more help then saying that
> it's meant to sort a list (which is obvioud by the function name anyway).
>
> --
> Sam
>
> Fifty years of programming language research, and we end up with C++ ???
> --Richard A. O'Keefe
>
-tmind-
http://www.geocities.com/SiliconValley/Lab/6888/langopts.htm
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 03 Feb 1999 22:26:13 GMT
From: topmind@technologist.com
Subject: Re: Perl Criticism
Message-Id: <79aids$4n4$1@nnrp1.dejanews.com>
Reply to Sam Holden:
> > I'll give an example using your code above...
>
> int a
> a = 10
> mysub(a)
> show a // result 10
>
> sub mysub(p)
> p = 20
> endsub
>
> So there we have identical code except one is dealing with an array and
> one is dealing with an integer. The mysub() call however is different,
> without any indication that will be different. One passes by reference the
> other passes by value.
>
> That is what happens when you try to hide things from the programmer. C++ does
> this by allowing you to pass references (as opposed to pointers), the problem
is
> that the calling code looks identical, the only way to know if a reference or
> by value is being used is to look at the function definition. This makes it
> harder to see what it is going on (but makes writing the original function
> much easier).
>
> If the language said mysub(\a) we would know it was passing by reference and
> if it said mysub(a) we would know it was passing by value. Unless it always
> passes by reference, or always passes by value.
>
On my webpage I propose having the subroutine definition, not
the caller, determine the by-value/by-reference choice.
This is how Pascal does it, for example. I cannot think
of a common reason to have the caller decide between
the two.
(Actually I propose something a little different, but I don't
want to go into that here.)
> > then a pointer must be used somewhere. The language may hide it from the
> programmer but they are there.
I am not talking about the implementation of the
language. For speed, interpreters must use all kinds of
unfriendly constructs inside, this is a given. It's all
one's and zero's at some level deep down.
> > So Java has pointers, you just can't do pointer arithmetic, and Java is
> strongly typed.
>
> So the question still stands : Name an OO language that doesn't use pointers?
>
I guess I am using an incorrect working definition of "pointers". My issue is
that Perlers have to rely on the "\" operator and it's equivalent more than
necessary. Perhaps you are used to it, but it just seems like more micro-
management of memory rather than dealing with algorithms and concepts. (Oops,
words like "seems" are going to get me in trouble with some of you.)
> >> >>> Of course a little evidence
> >on your part for you statements would be a novel idea. <<
> >
> >I am not the one who claimed they are necessary, so
> >I cannot provide the evidence. You would have to
> >tell me exactly what you use them for and I could
> >then show you an alternative.
>
> No but you made some statements without any backup. You claimed some things
> without bothering to give an example to back up your claim. I have simply
> asked for that backup, and you have provided it in this post.
>
How about you implement something in which you think they are necessary or
very helpful, and I will supply an alternative. Fair? I cannot read your mind
otherwise. I come here to kick ideas around, not play lawyer.
> > Using references in perl makes code much more readable than using
> soft-references.
'Tis so if you compare it to YOUR brand of soft references, such as the caller
determining the reference type above. Other approaches reduce or eliminate the
decision point of whether a reference indicator is needed or not.
> > I mean something along the lines of having a data structure which contains
> sub components which can be of many different types. When we want to
> walk the data structure for example we could do something like this :
>
> switch(n) {
> case (type1) : //do some stuff or call a function
> case (type2) : //do some stuff...
> case (type3) : //do some stuff...
> ...
> case (typeN) : //do some stuff...
> }
>
> Instead we could store a reference to the appropriate 'stuff' in the data
> structure and do :
>
> n->do_some_stuff();
I have pointed out in my anti-OOP webpages that OOP simply changes the
*nesting* and placement of case-like structures, not reducing them. It is a
clever illusion, but I see through it:
Traditional:
Method 1
Case A
Case B
Case C
Method 2
Case A
Case B
Case C
Method 3
Case A
Case B
Case C
OOP:
SubClass A
Method 1
Method 2
Method 3
SubClass B
Method 1
Method 2
Method 3
SubClass C
Method 1
Method 2
Method 3
As you can see, all OOP does is turn the shirt inside out, it does not reduce
the number of sleeves. The comb still has lots of teeth. (Some argue that
grouping by category is better than grouping by method, but I have seen no
objective evidence of such.)
> Because signatures are not production code, they are intentionally written
> to be hard to understand.
I rarely see cryptology contests in other languages. Why does Perl give one
the urge to make these? (Note before lighting your flames that I supplied no
answer.)
> Now I don't care much about efficiency, but I don't like sacrificing one thing
> for no gain. Here you are sacrificing the fast access of a reference, with
> some added information that the data is a reference and not something else,
and
> all you get in return is a different way of storing the reference.
But Perl does not make the second alternative very easy. I also find that if
the shebang fits in memory, then there is usually not a performance issue to
begin with. Thus, the memory-centric approach LACKS auto-persistence at the
expense of speed. I think slower and scalable is better than fast and size-
limited. Don't you? (Perhaps both approaches can be put into a language,
although it may bloat it.)
> That's fine you can do that, you shouldn't however do that at the expense of
> every other paradigm out there. I'm sure table-oriented programming is very
> useful, when your underlying data maps well onto tables. When it doesn't
though
> you are forcing a fit which makes the code less readable.
>
I find that most stuff maps quite well to T.O.P. Perhaps not video games, but
much business stuff certainly does. I just find that T.O.P. takes a lot of
the micro-management and grunt-work out of working with data collections,
especially if you don't want to worry about RAM limitations. However, it may
simply be a personal paradigm preference and there is no use having a
religious battle over it. (Then again, a paradigm Jihad might be fun. I think
some things remain in place out of tradition, not merit.)
-topmind- (top = table-oriented programming)
http://www.geocities.com/SiliconValley/Lab/6888/
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 03 Feb 1999 14:37:11 -0800
From: Michael Nanfito <mnanfito@ups.edu>
Subject: perl newbie: need help pasing web forms
Message-Id: <36B8CF97.4DD7501F@ups.edu>
Hi,
I have a script to parse web forms. It works fine except for
characters such as commas (,) and slashes (/). Takes text
fine and outputs it ok. But I want to collect some URLS
from people. This is what I get:
You suggested the URL: http%3A%2F%2Fwww.ups.edu
Here is the script I am using:
sub Parse_Form {
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
} else {
print "Content-type: text/html\n\n";
print "<P>Use Post or Get";
}
foreach $pair (@pairs) {
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C",
hex($1))/eg;
$value =~s/<!--(.|\n)*-->//g;
if ($formdata{$key}) {
$formdata{$key} .= ", $value";
} else {
$formdata{$key} = $value;
}
}
}
1;
thanks
Michael Nanfito
University of Puget Sound
------------------------------
Date: 3 Feb 1999 22:52:11 GMT
From: ftmom42@aol.com (FTMOM42)
Subject: Perl Path
Message-Id: <19990203175211.15204.00000194@ng-fc1.aol.com>
I am a newbie at perl and I want to know how to find the path to my perl
binary.
(i.e., usr/bin/perl or whatever.)
Is there a command flag that could tell me this?
I have Win98(sigh...)
and doqnloaded and installed perl successfully onto my system.
Could somebody help me out?
Please EMAIL me with your solution if you have one.
fthizsht@hotmail.com
------------------------------
Date: Wed, 03 Feb 1999 20:45:21 GMT
From: prabhashshrestha@my-dejanews.com
Subject: Re: perl/tk slow dialog mapping?? (fwd)
Message-Id: <79acgv$vl1$1@nnrp1.dejanews.com>
In article <Pine.LNX.3.95.990201234241.18000A-100000@crb.crb-web.com>,
wayne@crb-web.com wrote: Please help me with how to create pop up windows
from a script in client machine. I have a script that picks up the error
message that I want to display as pop up on client. Win32::MsgBox does not
seem to be the answer. Is there something else that I need to install. Any
sample scripts will be great help. Thank you.
> I have tested the perl/tk samples on three different linux machines and one
> HP. It seems that some windows popup and are filled with content instantly,
> but others (mainly dialogs) appear but I have to wait a few seconds for the
> text to appear in the dialog.
>
> Does anyone know how to remedy this situation?
>
> Thanks,
> Wayne
>
>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 03 Feb 1999 22:36:57 GMT
From: k2k2@my-dejanews.com
Subject: Re: problem forking with perl: child sometimes dies
Message-Id: <79aj29$57g$1@nnrp1.dejanews.com>
In article <F6K3qv.Gx@news.boeing.com>,
ced@bcstec.ca.boeing.com (Charles DeRykus) wrote:
>> I have a perl script that forks off a child to do some work in the
>> background that can take a long time. It works somthing like this:
>>
>>
>> if (!defined($child_pid = fork())) {
>> die "cannot fork $!\n";
>> } elsif ($child_pid) { #parent process
>> print "this is the parent";
>> } else { #child process
>> open STDERR, ">/dev/null"; #must close STDERR & STDOUT or the
>> open STDOUT, ">/dev/null"; # process will wait for the fork
>> # before finishing if run via CGI.
>> open (LOG, ">$logfile")||die "Can't open $logfile: $!\n";
>> flock(LOG,2);
>> select LOG; #LOG is default filehandle now
>> $| =1;
>> print "this is the child\n";
>> &write_a_bunch_of_data_to_some_files;
>> }
>>
>> This script works fine on my machine. However, when I upload it to my ISP's
>> machine, the parent runs fine, but the child dies at some point. It writes
>> some of the files its supposed to, but never quite finishes. It dies in
>> different places each time its run.
>>
>> If I run it on my ISP's machine without the fork, it works fine.
>>
>> If I replace &write_a_bunch_of_data_to_some_files;
>> with &write_LESS_data_to_some_files;
>>
>> ...the child has a better chance of finishing but still usually dies before
>> completion.
>>
>> My machine:
>> Linux mymachine.com 2.0.35 #1 Tue Jul 14 23:56:39 EDT 1998 i686 unknown
>> This is perl, version 5.004_04 built for i386-linux
>>
>> My ISP's machine:
>> Linux myisp.com 2.0.35 #3 Mon Jul 20 10:51:25 PDT 1998 i686
>> This is perl, version 5.004_01
>>
>> If anybody can help me I'd really appreciate it. Thanks in advance.
>
> Here's a vague possilibility:
>
> $SIG{HUP} = 'IGNORE' # add to child
>
> hth,
> --
> Charles DeRykus
>
Hmm. Nope, that doesn't seem to make any difference... any other ideas?
Thanks.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 03 Feb 1999 22:21:17 GMT
From: dragnovich@my-dejanews.com
Subject: Read emails from a perl program
Message-Id: <79ai4m$4ie$1@nnrp1.dejanews.com>
Hello folks!
I want to make a program that will be residing under my FreeBSD server. This
program will do this simple task:
Stay on the server crontab, if a NEW email comes to my account it detects it!
get the Sender data and subject of the email (not marking it as readed) and
send this data to me, to tell me that I have a mail! =-) Lets say to my ICQ,
or to my chat channel or to my AOL Instant Mesenger or if IM REALY, REALY
NOT ONLINE to my pager! (Yea.. Yea.. there are MANY applications that do
thing like this.. but I want to do it by the hard way programming it my self,
OK!) =-)
Well I know How to do the send data part! but How can I detect that a new mail
has arrived? how to read the From : camp and the Subject : camp ?? That's all
that I need!
------------------------
Juan Carlos Lopez
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 03 Feb 1999 22:23:59 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Simple Perl Script
Message-Id: <304u2.11$_E3.3664@nsw.nnrp.telstra.net>
In article <36B870DE.F005A0B9@prism.gatech.edu>,
Stuart Lester <gt3511a@prism.gatech.edu> writes:
> Hey out there,
> Does anyone happen to know how to get perl to do the following (when
> passed a filename and string):
> Search the entire file <filename> for the string. When found the ENTIRE
# perldoc -f open
# perldoc perlop
(find the section on I/O operators)
# perldoc -f grep
# perldoc perlre
> line is deleted. Repeat for all instances of <string>.
open the file
open output file
read each line
output the line if the keyword doesn't live in here
close files
delete the old file
rename the new file
> I am pretty sure this would only be a simple script, but i don't know
> the syntax to delete an entire line.
# perl -ni -e 'print unless /regexp/' filename
replace regexp with a regular expression (or just a string, possibly
between \Q and \E), replace filename with the filename you want to
process.
# perldoc perlre
# perldoc perlrun
as a 'script'
#!/usr/local/bin/perl -ni
print unless /regexp/;
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | Can't say that it is, 'cause it ain't.
NSW, Australia |
------------------------------
Date: Wed, 03 Feb 1999 15:57:58 -0600
From: Scott Dummer <scott.dummer@noaa.gov>
Subject: Re: UNIX 'tail' command in Perl??
Message-Id: <36B8C665.323FB787@noaa.gov>
Peter Smith wrote:
> I have a 650MB text file with 162,000 recortds that I need to do
> something with - I haven't yet been able to open with Access/Excel/etc.
> Soooooo, I thought I might be able to chop it up using the tail
> command. I don't have access to a UNIX box, however.
>
> So I need an efficient tail command so I can chop off the last x
> thousand records. How do I use Perl to get the last 10 records?
>
> open(FILE,"<mybigfile");
> seek(eof); //??
> read backwards??
>
> Thanks for any hints!
Try:
$i = 0;
open(FILE,"<mybigfile");
while(<IN>) {
$i++;
}
close IN;
# There are $i lines in file (0-n lines)
$tail_nmbr = 5; #no. lines wanted to access e.g. "tail -5"
$nmbr = $i - $tail_nmbr;
$i = 0;
open(FILE,"<mybigfile");
while(<IN>) {
$i++;
if ($i > $nmbr) {print $_;}
}
close IN;
exit;
I don't know if this the most efficient way of doing what you want it, but
it works on my system.
Scott D.
------------------------------
Date: Wed, 03 Feb 1999 14:03:05 -0600
From: James Ludlow <ludlow@us.ibm.com>
Subject: Re: Unlink Symlink
Message-Id: <36B8AB79.D95402E0@us.ibm.com>
Artoo wrote:
> How can you delete (unlink) a symlink?
> I've tryied using unlink ($symlink_path) and it does nothing, what function
> to I need to use?
Did you check $! to see why it failed?
unlink($symlink_path) or die "Error unlinking $symlink_path: $!";
--
James Ludlow (ludlow@us.ibm.com)
(Any opinions expressed are my own, not necessarily those of IBM)
------------------------------
Date: Wed, 03 Feb 1999 16:30:21 -0500
From: Tripp Lilley <tripp.lilley@perspex.com>
Subject: Re: Using a variable as a variable name
Message-Id: <36B8BFED.40B04EC@perspex.com>
Bruce Hodo wrote:
> 1 foreach (@javadbfieldnames) {
> 2 no strict 'refs';
> 3 $varname= '$'.$_;
> 4 $$varname = $fields[$fieldno];
> 5 $fieldno++;
> 6 }
In line 3, you're prepending a '$'. No need.
$variable_name = 'foo';
$$variable_name = 42;
print "$foo\n";
output:
42
DISCLAIMER: I only use symbolic references when it's deep black magic I
seek, and usually not even then, since the magic is usually deep enough
that I might as well be mucking about with the symbol table. As others
have suggested, there's got to be a better way to do what you want :-)
Consider, for instance, a tied hash that retrieves and caches the DB
values, and provides reasonable defaults in case someone removes a value
from the DB table that your program expects.
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 4818
**************************************