[14068] in Perl-Users-Digest
Perl-Users Digest, Issue: 1478 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 24 12:12:15 1999
Date: Wed, 24 Nov 1999 09:10:37 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <943463437-v9-i1478@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 24 Nov 1999 Volume: 9 Number: 1478
Today's topics:
Need Design Guidance <rhino@wwdc.com>
Re: Need Design Guidance <lr@hpl.hp.com>
Re: Need Design Guidance <jeff@vpservices.com>
Re: Need Design Guidance <lr@hpl.hp.com>
Net::Ping <s184314@kub.nl>
Re: New dialect of perl: xperl (or reinventing perl, or (Abigail)
Re: New dialect of perl: xperl (or reinventing perl, or (Abigail)
Re: Outputting "#" in URL for anchoring ether_nut@my-deja.com
Parallel User Agent Swaroop.Kumar@bellhowell.infolearning.com
Perl doesn't like SIGCHLD <mayers@psi.com>
Perl Module or Hooks for wait3() system call? kov@mit.edu
Perl, IIS4.0, WinNT4, and Printing... <gary@guildhallleisure.com>
Re: Please help... a problem with Perl & MySQL!! (Steve Morris)
Re: Please! Help with hashes within hashes!!!! <dbartmess@netlibrary.com>
Re: Portuguese Whaling Songs (David Cantrell)
Re: Portuguese Whaling Songs lee.lindley@bigfoot.com
Printing on LPT1 or COM1 on NT Perl rsd@aol.com
Re: Refining code <nigh_postal@my-deja.com>
Re: reg expr question <roman.stawski@fr.adp.com>
Re: reg expr question (Tad McClellan)
Re: reg expr question <lr@hpl.hp.com>
Re: reg expr question <vincent.murphy@cybertrust.gte.com>
Re: reg expr question <lr@hpl.hp.com>
Re: reg expr question <uri@sysarch.com>
Re: reg expr question (Abigail)
Re: sprintf help <skilchen@swissonline.ch>
Re: Test for eval() without using eval() ?? <montuori@acs.neu.edu>
Re: Test for eval() without using eval() ?? <mkruse@rens.com>
Re: Test for eval() without using eval() ?? <mkruse@rens.com>
Tiny MacPerl Script <jason.holland@dial.pipex.com>
Traversing Inheritance Tree <jason.holland@dial.pipex.com>
Re: using regex to extract data <jason.dreyerNOjaSPAM@home.com.invalid>
Re: using regex to extract data <jason.dreyerNOjaSPAM@home.com.invalid>
Re: using regex to extract data <jason.dreyerNOjaSPAM@home.com.invalid>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 24 Nov 1999 09:54:55 -0500
From: "Rhino" <rhino@wwdc.com>
Subject: Need Design Guidance
Message-Id: <4XS_3.2040$qy2.12194@newsfeed.slurp.net>
I'm a Perl newbie who has programmed in several other languages. I need some
suggestions on the best Perl design for a situation I am trying to handle.
I am reading in a flat file which contains umpteen lines. Each line of the
file contains four values, delimited with semicolons, in the exact same
order, namely Date, Topic, Author, and Type. The Date column always contains
a unique value but the remaining columns will often contain duplicates. I
want to display the data on a web page in the form of an HTML table with the
same four columns.
I also want to be able to present the data sorted by any column of the
table, ascending or descending. I've already created a form that prompts the
user for a sort column and direction and it works fine.
What is my best approach to storing and sorting the data? I was thinking
about reading the data into a two-dimensional array so that it looked like
this:
DATE TOPIC AUTHOR TYPE
1983-12 Dune Herbert Book
1984-01 1984 Orwell Film
1984-02 Cyberia Enoon Story
1984-03 Time Dann Book
Then, using the sort column and direction specified by the user, I was going
to use a subroutine to split the array into a hash of hashes so that the
desired sort key is the key of the hash and the remaining data is in an
anonymous hash within the value of the key. For example, if the user wanted
to sort the table by Author, the hash would look like this if declared using
literals (which I don't plan to do, I'm just trying to make the idea clear):
%Temp=("Herbert" => {Date => "1983-12", Topic => "Dune", Type => "Book"},
"Orwell" => {Date => "1984-01", Topic => "1984", Type => "Film"},
"Enoon" => {Date => "1984-02", Topic => "Cyberia", Type =>
"Story"},
"Dann" => {Date => "1984-03", Topic => "Time", Type => "Book"}
);
I would then copy the keys to a single dimensional array, sort them, reverse
the sort if it was a descending sort, then do a loop that would use the
sorted key array to write out the key column in sequence and simultaneously
look up the remaining values for that key.
Does that sound like a good design or are there better ways to do this in
Perl? I am NOT looking for the cutest way of doing it: I would prefer a
straightforward and clear approach that is a bit inefficient to one that is
really efficient but unmaintainably concise.
Please copy my e-mail address with your answer if you can.
Thanks in advance!
---
rhino@wwdc.com
Pembleton (to imaginary suspect): Son, you are ignorance personified!
Homicide: Life on the Street
SPAM catcher: postmaster@127.0.0.0
------------------------------
Date: Wed, 24 Nov 1999 08:41:46 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Need Design Guidance
Message-Id: <MPG.12a5b528a9826aea98a274@nntp.hpl.hp.com>
[Posted and a courtesy copy sent as requested.]
In article <4XS_3.2040$qy2.12194@newsfeed.slurp.net> on Wed, 24 Nov 1999
09:54:55 -0500, Rhino <rhino@wwdc.com> says...
> I am reading in a flat file which contains umpteen lines. Each line of the
> file contains four values, delimited with semicolons, in the exact same
> order, namely Date, Topic, Author, and Type. The Date column always contains
> a unique value but the remaining columns will often contain duplicates. I
> want to display the data on a web page in the form of an HTML table with the
> same four columns.
>
> I also want to be able to present the data sorted by any column of the
> table, ascending or descending. I've already created a form that prompts the
> user for a sort column and direction and it works fine.
>
> What is my best approach to storing and sorting the data? I was thinking
> about reading the data into a two-dimensional array so that it looked like
> this:
> DATE TOPIC AUTHOR TYPE
> 1983-12 Dune Herbert Book
> 1984-01 1984 Orwell Film
> 1984-02 Cyberia Enoon Story
> 1984-03 Time Dann Book
>
> Then, using the sort column and direction specified by the user, I was going
> to use a subroutine to split the array into a hash of hashes ...
<SNIP> of design involving rewriting data structures
> Does that sound like a good design or are there better ways to do this in
> Perl? I am NOT looking for the cutest way of doing it: I would prefer a
> straightforward and clear approach that is a bit inefficient to one that is
> really efficient but unmaintainably concise.
You can do anything you want to directly with the array of array
[reference]s that you have already created. Here is a sketch of the
solution:
#!/usr/local/bin/perl -w
use strict;
my $column = 2;
my $reverse = 1;
my @data = (
[ qw( 1983-12 Dune Herbert Book ) ],
[ qw( 1984-01 1984 Orwell Film ) ],
[ qw( 1984-02 Cyberia Enoon Story ) ],
[ qw( 1984-03 Time Dann Book ) ],
);
my @out = sort { $a->[$column] cmp $b->[$column] } @data;
@out = reverse @out if $reverse;
print map "@$_\n", @out;
> Please copy my e-mail address with your answer if you can.
Done.
> Thanks in advance!
You're welcome.
> ---
The proper 'sigdash' is this string: "\n-- \n"
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 24 Nov 1999 15:54:15 GMT
From: Jeff Zucker <jeff@vpservices.com>
To: Rhino <rhino@wwdc.com>
Subject: Re: Need Design Guidance
Message-Id: <383C09D2.E41E13CC@vpservices.com>
[posted and mailed]
Rhino wrote:
>
> I'm a Perl newbie who has programmed in several other languages. I need some
> suggestions on the best Perl design for a situation I am trying to handle.
>
> I am reading in a flat file which contains umpteen lines. Each line of the
> file contains four values, delimited with semicolons, in the exact same
> order, namely Date, Topic, Author, and Type. The Date column always contains
> a unique value but the remaining columns will often contain duplicates. I
> want to display the data on a web page in the form of an HTML table with the
> same four columns.
>
> I also want to be able to present the data sorted by any column of the
> table, ascending or descending.
The hash and array stuff you are trying is one way to do it. The most
powerful way however is to use the DBI module (generic Perl Database
Interface works with almost any database) along with DBD::CSV (the
comma-separated-values driver for DBI). You can set the delimeter to be
semicolon instead of comma, then you can use SQL statements to sort,
query, etc. This will both allow you to do more powerful stuff on the
files you have and also allow you to painlessly move from text files to
real databases if the need arises.
> Please copy my e-mail address with your answer if you can.
Well, ok, but you really should read the answers in the newsgroup, there
are alot wiser heads than me in here.
--
Jeff
------------------------------
Date: Wed, 24 Nov 1999 08:56:07 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Need Design Guidance
Message-Id: <MPG.12a5b881317e75b098a275@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <MPG.12a5b528a9826aea98a274@nntp.hpl.hp.com> on Wed, 24 Nov
1999 08:41:46 -0800, Larry Rosler <lr@hpl.hp.com> says...
...
> #!/usr/local/bin/perl -w
> use strict;
>
> my $column = 2;
> my $reverse = 1;
> my @data = (
> [ qw( 1983-12 Dune Herbert Book ) ],
> [ qw( 1984-01 1984 Orwell Film ) ],
> [ qw( 1984-02 Cyberia Enoon Story ) ],
> [ qw( 1984-03 Time Dann Book ) ],
> );
>
> my @out = sort { $a->[$column] cmp $b->[$column] } @data;
>
> @out = reverse @out if $reverse;
>
> print map "@$_\n", @out;
I omitted the canonical reference to perlfaq4: "How do I sort an array
by (anything)?"
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 24 Nov 1999 14:40:24 GMT
From: Bas van Gils <s184314@kub.nl>
Subject: Net::Ping
Message-Id: <81gtco$ong$1@mailnews.kub.nl>
Hello Guru's ;-)
I've been trying to work with the Net::Ping packages. The script I used (more
or less copied from the cookbook) looks like this:
#!/usr/local/bin/perl
$host = "stuwww.kub.nl";
use Net::Ping;
$p = Net::Ping->new()
or die ("Can't create new ping object: $!\n");
print "$host is alive\n" if $p->ping($host);
$p->close;
This did NOT work .. surprise surprise. The error I get looks like this:
bad arg length for Socket::unpack_sockaddr_in, length is 0, should be 16 at
/usr=/lib/perl5/site_perl/i386-linux/Socket.pm line 236.
I haven't got a clue what goes wrong. I've even re-installed the Net::Ping
module as well as the Socket-module.
Suggestions, Anyone ???
thanx a million in advance
Bas van Gils
--
Bas van Gils (b.vangils@kub.nl) http://stuwww.kub.nl/people/b.vangils
tel# +31-6-24614919 (also SMS) fax# +49-89-2443-61693
System Administrator of StuWWW at http://stuwww.kub.nl/
Student of Information Management and Technology at Tilburg University
------------------------------
Date: 24 Nov 1999 10:16:24 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: New dialect of perl: xperl (or reinventing perl, or perl-izing jpython)
Message-Id: <slrn83o40s.m2v.abigail@alexandra.delanet.com>
Bart Lateur (bart.lateur@skynet.be) wrote on MMCCLXXVI September MCMXCIII
in <URL:news:383eeab7.8253799@news.skynet.be>:
:: Abigail wrote:
::
:: >With OO perl, there's just one living room for each object. The entire
:: >tree of inherited classes all share the same livingroom.
::
:: That could easily be fixed, if everybody were to use a class specific
:: prefix for it's fields names.
But that's the entire point I'm making. "IF everybody". If everyone would
do it a specific way, the language should have done that for us. But no,
the language gives you 214743270955760987609 ways to implement objects,
the default way sucks badly, and that's why Perl-OO is utterly useless.
I'm familiar with the trick. The trick requires extra work, and it requires
cooperation *DONE IN ADVANCE*. It's making easy things hard. It's not
Perl. It's anti-Perl.
It might be an interesting exercise to go out to CPAN and see how many
object there actually bother to use this trick. I doubt it will be 50%.
Abigail
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 24 Nov 1999 10:19:35 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: New dialect of perl: xperl (or reinventing perl, or perl-izing jpython)
Message-Id: <slrn83o46q.m2v.abigail@alexandra.delanet.com>
Bart Lateur (bart.lateur@skynet.be) wrote on MMCCLXXVI September MCMXCIII
in <URL:news:383dea43.8137688@news.skynet.be>:
?? Abigail wrote:
??
?? >no
?? >lexical scoped 'array', and if you type 'arrya', it's not even a run
?? >time error. You can use all the -w and use stricts you want, all you
?? >get is mysterious behaviour. Sure, sure, sure, you can put in extra
?? >checks. But that's something I want from the *language*, after all,
?? >that's what "use strict" is doing for me for non-OO.
??
?? I've done a little exercise using tied hashes, which could help.
Been there, done that, doesn't really work. Try using that on something
you inherit. Or try inheriting something that uses that. It's the
implementation becoming interface again.
Face it, Perl-OO sucks, no matter how many tricks you invent.
Abigail
--
perl -wle\$_=\<\<EOT\;y/\\n/\ /\;print\; -eJust -eanother -ePerl -eHacker -eEOT
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Wed, 24 Nov 1999 15:57:33 GMT
From: ether_nut@my-deja.com
Subject: Re: Outputting "#" in URL for anchoring
Message-Id: <81h1tb$usr$1@nnrp1.deja.com>
Let me re-phrase the origional question. It works embedding a url
with an anchor using print "http//.../index.html?#AZ\">\n"; in IE only.
Netscape just spits out /index.html? and ignores the whole anchor.
Here is the actual line of code.
#!/usr/bin/perl
#
if ($test eq 'myoutput')
{
print "<FORM METHOD=\"GET\"
ACTION=\"http://mydomain.com/index.html?#AZ\">\n";
print "<li><b><i> Search for Results<br></b></i>\n";
print "<input type=\"SUBMIT\" value=\"Show New Results\">\n";
print " </form></b></i>\n";
}
ether_nut
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 24 Nov 1999 15:39:56 GMT
From: Swaroop.Kumar@bellhowell.infolearning.com
Subject: Parallel User Agent
Message-Id: <81h0sc$u7d$1@nnrp1.deja.com>
Hi:
I'm trying to use the Parallel User Agent to fetch pages from my web
site. The 'man' page for LWP::Parallel doesn't explain what the
parameter to the 'register' method should be. In the examples shown, it
seems to be an anonymous array of HTTP::Reqest objects. I would like to
know if the anonymous array is a requirement or if I can use an ordinary
array of HTTP::Request objects. I would greatly appreciate it if you
could illustrate the usage of the Parallel User Agent with an example.
Thanx in advance,
Swaroop
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 24 Nov 1999 11:42:36 -0500
From: "Mayer, Shane" <mayers@psi.com>
Subject: Perl doesn't like SIGCHLD
Message-Id: <383C157B.7D145BA0@psi.com>
This is not a question, just an experience I had with a script recently
that hopefully will help someone else out.
I wrote a monitoring system that needed to fork off about 15 children in
order to finish all of its work in the amount of time required
(basically it had to perform about 1000 pings in less than 10 minutes).
So I wrote the script, debugged it, and ran it as a cron job every 10
minutes. At first it appeared to run great, then after a day or so it
started producing crazy errors, for example:
############
Your "cron" job on monitor.troy.psi.com
/opt/PSItrunkm/bin/collect_stats.cron
produced the following output:
Caught a SIGSEGV at /opt/PSItrunkm/bin/collect_stats.cron line 611
$ = main::process_results() called from file
`/opt/PSItrunkm/bin/collect_stats.cron' line 168
Abort - core dumped
###########
where line 611 was
foreach $mibres ( (\%INMIBres, \%OUTMIBres) ) {
and both %INMIBres and %OUTMIBres were undoutedly defined
even more annoying was this error message:
#######################
Your "cron" job on monitor.troy.psi.com
/opt/PSItrunkm/bin/collect_stats.cron
produced the following output:
panic: leave_scope inconsistency at
/opt/PSItrunkm/bin/collect_stats.cron line 636.
panic: leave_scope inconsistency.
panic: leave_scope inconsistency.
###########################
since the camel says you should never see a panic: leave_scope
inconsistency error
The point of this story is, I removed the SIGCHLD handler, and replaced
it with a function that was periodically called that used the following
code to look for zombies.
foreach $pid ( keys %childrenpids ) {
if ( kill( 0, $pid ) ) {
if ( waitpid( $pid, WNOHANG ) != 0 ) {
logit( "Found defunct child process $pid" );
delete $childrenpids{$pid};
} else {
logit( "No zombie found for child process $pid" );
delete $childrenpids{$pid};
}
}
Where %childrenpids was a hashed using the pids of each childrne.
This apperently has fixed the problem since it has not crashed in over a
week (as opposed to 2 or 3 times a day).
MORAL: SIGCHLD handlers were not dependable for me using perl version
5.004_01 on Solaris.
Shane Mayer
------------------------------
Date: Wed, 24 Nov 1999 14:50:07 GMT
From: kov@mit.edu
Subject: Perl Module or Hooks for wait3() system call?
Message-Id: <81gtut$rtj$1@nnrp1.deja.com>
For those not familiar, wait3() and wait4() are like wait() and
waitpid() except they give access to cool structs that tell the resource
usage of the process you waited for, and status information (if it's
zombie, stopped and what caused it).
I can't find anything in CPAN, this NG, and a grep through my lib/perl5.
(But I can dream, can't I?)
Anyone tried this? I've never written glue-code before, but this makes
me want to.
-- kov
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 24 Nov 1999 15:52:07 -0000
From: "Gary Thomlinson" <gary@guildhallleisure.com>
Subject: Perl, IIS4.0, WinNT4, and Printing...
Message-Id: <81h1it$n71$1@gxsn.com>
Is there any easy way to send streamed text to a printer when running on
NT4/IIs4.0. Currently I can use a map or redirection of LPT2 etc and stream
text out of a perl script, but after a while, NT seems to 'disconnect' the
mapping and I can't open the stream for output, not even using the path
\\server\printernnn
Any ideas?
Cheers
Gary Thomlinson
Programmer with flat forehead and dented walls...
------------------------------
Date: 24 Nov 1999 14:54:16 GMT
From: morris@rahul.net (Steve Morris)
Subject: Re: Please help... a problem with Perl & MySQL!!
Message-Id: <81gu6o$ehj$1@samba.rahul.net>
In article <81gq9q$l21$1@sunb.ocs.mq.edu.au>, "Brendan Reville"
<breville@mpce.mq.edu.au> writes:
> hi everyone,
>
> I am having a problem getting my Perl program to access a MySQL
> database. My test program looks like this:
>
> use DBI;
>
> $serverPort = "3308";
>
> $dbh = DBI->connect('dbi:MySQL:Clients;port=$serverPort',
> 'mydatabase', 'mypassword');
While this may not be your entire problem, you have your strings in the
connect line in single quotes. This means that $server is not being
interpolated. Try double quotes.
HTH
Steve Morris
------------------------------
Date: Wed, 24 Nov 1999 09:53:40 -0700
From: "David A. Bartmess" <dbartmess@netlibrary.com>
Subject: Re: Please! Help with hashes within hashes!!!!
Message-Id: <81h591$73o$1@fir.prod.itd.earthlink.net>
Thanks, I'll check it out...
Uldoz wrote in message <19991123234903.03896.00001613@ng-fy1.news.cs.com>...
>In the mean time I suggest you read in the Blue Camel pages 257 to 275.
Page
>270 is where HoH are discussed. See in the perl docs perlLoL section for
>another source of the same info.
------------------------------
Date: Wed, 24 Nov 1999 14:01:46 GMT
From: NukeEmUp@ThePentagon.com (David Cantrell)
Subject: Re: Portuguese Whaling Songs
Message-Id: <383bee6d.7630151@10.0.0.155>
On 24 Nov 1999 11:29:57 GMT, Jonathan Stowe <gellyfish@gellyfish.com>
said:
>Gwlad, gwlad, pleidiol wyf i'm gwlad
>Tra mor yn fur
>I'r bur hoff bau
>O bydded i'r heniaith barhau.
use Lingua::Cymraeg::Pronunciation;
Kernel panic - not enough phlegm
--
David Cantrell, part-time Unix/perl/SQL/java techie
full-time chef/musician/homebrewer
http://www.ThePentagon.com/NukeEmUp
------------------------------
Date: 24 Nov 1999 14:43:25 GMT
From: lee.lindley@bigfoot.com
Subject: Re: Portuguese Whaling Songs
Message-Id: <81gtid$4io$1@rguxd.viasystems.com>
Abigail <abigail@delanet.com> wrote:
:>Jeff Zucker (jeff@vpservices.com) wrote on MMCCLXXV September MCMXCIII in
:><URL:news:383B22CD.6E8E48F0@vpservices.com>:
:>,,
:>,, Ah, but I can find the Perl content in the message:
:>,,
:>,, $msg = 'Portugese Whaling Songs';
:>,, $msg =~ s/^(.).(.)...(.)......(.).*$/$1$3$2$4/;
:>,,
:>,, Making a better re to do that is left as an exercise for the reader.
:> $msge =~ s/.*/Perl/;
/(?{$msge='Perl'})/;
Not a re, but (ab)uses the re engine.
In the current stable version of Perl, pos() is always '' (or undef?)
inside (?{}), so this is cheating.
$msge =~ /^.(?{substr($msge,pos()) = 'Perl'})/;
Just imagine what you could do if $&, $1 and company were Lvalues
back into the matched string.
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: Wed, 24 Nov 1999 15:48:09 GMT
From: rsd@aol.com
Subject: Printing on LPT1 or COM1 on NT Perl
Message-Id: <383c0745.8612444@news.virgin.net>
Does any one know how to send prints directly to the
printer either on LPT1 or COM1.
I could not find any reference to it in the Perl Docs.
I have a requirement to send single lines of text immediately to the
printer, which is a dot matrix printer, for information alarms.
I tried sending to a file and then printing a file using system(print
/D:com1 filename), but this ends up printing the whole page, even if
there is only 1 line of text.
thanks
Russ Parker
------------------------------
Date: Wed, 24 Nov 1999 15:21:55 GMT
From: nigh_postal <nigh_postal@my-deja.com>
Subject: Re: Refining code
Message-Id: <81gvqd$tas$1@nnrp1.deja.com>
In article <xkfd7t1w051.fsf@valdemar.col.hp.com>,
Eric The Read <emschwar@rmi.net> wrote:
> nigh_postal <nigh_postal@my-deja.com> writes:
> > Thanks Eric. I understand that it would be better to use a hash to
> > store the fields, and I have even done so in the past (for minor
parts
> > of the programs), it was just that to make the use of hashes
program-
> > wide (2000+ lines), it would require a great deal more typing.
>
> I'm sorry, but that's an argument I have absolutely no sympathy with.
> Adding clear, well-written comments takes a lot of typing, too, but
> anybody who'd use that as an excuse not to write them is just itching
to
> get fired, in my book.
>
It wasn't an argument. I was just explaining why I have not converted
to hashes in the past. At that point I new that hashes were better,
but I did not realize that symbolic references were "A Bad Thing". If
I weren't willing to make extensive changes to my code at this point,
then I wouldn't be posting here asking for suggestions. I'm not a fan
of wasting mine or anybody else's time. It is just a habit I have of
explaining everything.
> > {$fields [$i]} turns into $tmp{$fields[$i]}, and thus to retrieve an
> > individual field it is $tmp{'NDX_NAME'} instead of $NDX_NAME. A
pain
> > when you have 7 different database structures with 20 fields each :P
>
> An even bigger pain for the poor bastard who has to pick up your code
in
> 5 months, after you've gone on to bigger and better things, and has to
> figure out how to make heads or tails of this.
>
This is true.
> Better to spend an extra four lousy keystrokes for the benefit of
writing
> clear, maintainable code, than to abbreviate to save yourself a few
> seconds of typing, and cost someone else several hours of confusion.
*nod* I agree.
Of
> course, using a more descriptive name than "tmp" is ideal-- unless
that's
> the name of your database, or some such thing.
Of course. Was just using it for demonstrative purposes.
>
> Programming is communication-- not only between the programmer and the
> user of that program (as mediated by the compiler/interpreter), but
also
> between the original programmer and the next person to hack it. Just
as
> you wouldn't talk to your boss in gutter slang, so you should avoid
it in
> your programming. Think of symrefs like ethnic insults-- just because
> Don Rickles can tell 'em doesn't mean you can get away with it.
>
Agreed. I now see the evil that is symrefs. I must push away the
temptation to follow the dark path.
> > Although I personally have never had any problems debugging the code
> > because of my use of symbolic references, I realize that in the
future
> > it may be somebody else who is modifying my code who has no clue
what
> > to watch out for. So in that respect it would be a good idea to
move
> > to the hash.
>
> That, and it would make your code more 'use strict;'-compliant.
Which is
> A Good Thing(tm) for readability, and maintainability.
Admittedly I have not used strict before. I know some of the
restrictions it poses, but I will have to delve into the perldocs do
get the skinny on the details. The -w option I have used, just not
extensively. It usually just gives me the expected warnings with me
using symrefs ($VARIABLE only used once, may be typo.. yada yada). A
couple times it has helped me debug my code.
>
> > I am also looking into the possibility of moving to an OO
> > version of the program, but as of yet I am not familiar enough with
it
> > to warrant an attempt.
>
> I'd get clear on the benefits of '-w' and 'use strict;' first. After
you
> can write code that is compliant with both of those, then maybe you
could
> look into OO. But I'm with Abigail on this one: Perl OO is neither
Perl,
> nor OO.
I have heard this. I'm not sure why people care so much about what it
is or isn't though. I tend to look at these things in terms of their
usefulness, not what category they happen to fall under. But then
again, I do not know how useful Perl OO that is neither Perl nor OO is
at this time so perhaps I should shut up :P
-Cody
---------------------------------------------------------
"Luke... Join the Dark Side, we have better benefits."
- JW
---------------------------------------------------------
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 24 Nov 1999 14:29:34 +0100
From: Roman Stawski <roman.stawski@fr.adp.com>
Subject: Re: reg expr question
Message-Id: <383BE83E.6DB2CE21@fr.adp.com>
Magnus Johansson wrote:
>
> If I want to check if a text only contains characters a-z how should I
> do then?
Two ways spring to mind:
1. use something like this:
#!perl -w
use strict ;
sub a2z{
return 1+$#{[map{return''if $_ lt chr(97)or(0x7a<ord)}split'',shift]};
}
print a2z(shift) ? 'good' : 'bad' ;
__END__
Note: that you'd have to do some work for lowercase letters with
accents. But, to
the best of my knowledge, it IS y2k compliant.
2. perldoc perlre
(where you might find something cleaner such as $a=~/^[a-z]*$/?1:0; )
------------------------------
Date: Wed, 24 Nov 1999 04:49:27 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: reg expr question
Message-Id: <slrn83nd57.d67.tadmc@magna.metronet.com>
On Wed, 24 Nov 1999 08:51:33 GMT, Magnus Johansson <di5majo@my-deja.com> wrote:
>If I want to check if a text only contains characters a-z how should I
>do then?
print "text is OK\n" if $text =~ /^[a-z]*$/;
or
print "text is OK\n" unless $text =~ /[^a-z]/;
But I think that a lot of "texts" might contain spaces, and
thus fail that test...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 24 Nov 1999 07:11:21 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: reg expr question
Message-Id: <MPG.12a59ff5fccf2c6398a271@nntp.hpl.hp.com>
In article <81g8ul$dmv$1@nnrp1.deja.com> on Wed, 24 Nov 1999 08:51:33
GMT, Magnus Johansson <di5majo@my-deja.com> says...
> If I want to check if a text only contains characters a-z how should I
> do then?
Assuming the string is in $_:
Slower way:
/^[a-z]*\z/ and print "Yes.\n";
Note '\z' not '$', to deal with the string "\n" (false, contains a
character other than [a-z]).
perldoc perlre
Faster way:
! tr/a-z//c and print "Yes.\n";
perldoc perlop
Each of those considers the null string ("") to satisfy the condition.
If this isn't desired, change '*' to '+' in the regex, or add a length()
test for the translate operation.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 24 Nov 1999 15:43:32 GMT
From: Vincent Murphy <vincent.murphy@cybertrust.gte.com>
Subject: Re: reg expr question
Message-Id: <xjg903n51zv.fsf@gamora.ndhm.gtegsc.com>
>>>>> "Larry" == Larry Rosler <lr@hpl.hp.com> writes:
Larry> In article <81g8ul$dmv$1@nnrp1.deja.com> on Wed, 24 Nov 1999 08:51:33
Larry> GMT, Magnus Johansson <di5majo@my-deja.com> says...
>> If I want to check if a text only contains characters a-z how should I
>> do then?
Larry> Assuming the string is in $_:
Larry> Slower way:
Larry> /^[a-z]*\z/ and print "Yes.\n";
------------------------^
At first I thought this was wrong, but I tested it and sure enough it
works. I looked at perlre and nowhere did it say \z. \Z yes, but not
\z. Where is this little pearl?
--Vinny
------------------------------
Date: Wed, 24 Nov 1999 08:07:59 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: reg expr question
Message-Id: <MPG.12a5ad359a010a0998a272@nntp.hpl.hp.com>
In article <xjg903n51zv.fsf@gamora.ndhm.gtegsc.com> on Wed, 24 Nov 1999
15:43:32 GMT, Vincent Murphy <vincent.murphy@cybertrust.gte.com> says...
> >>>>> "Larry" == Larry Rosler <lr@hpl.hp.com> writes:
>
> Larry> In article <81g8ul$dmv$1@nnrp1.deja.com> on Wed, 24 Nov 1999 08:51:33
> Larry> GMT, Magnus Johansson <di5majo@my-deja.com> says...
> >> If I want to check if a text only contains characters a-z how should I
> >> do then?
>
> Larry> Assuming the string is in $_:
>
> Larry> Slower way:
>
> Larry> /^[a-z]*\z/ and print "Yes.\n";
> ------------------------^
> At first I thought this was wrong, but I tested it and sure enough it
> works.
No surprise to me. I tested it too. :-)
> I looked at perlre and nowhere did it say \z. \Z yes, but not
> \z. Where is this little pearl?
Well, gawrsh, I didn't invent it!
<QUOTE>
Perl defines the following zero-width assertions:
\b Match a word boundary
\B Match a non-(word boundary)
\A Match only at beginning of string
\Z Match only at end of string, or before newline at the end
\z Match only at end of string
\G Match only where previous m//g left off (works only with /g)
</QUOTE>
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 24 Nov 1999 11:23:25 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: reg expr question
Message-Id: <x7k8n7luyq.fsf@home.sysarch.com>
>>>>> "VM" == Vincent Murphy <vincent.murphy@cybertrust.gte.com> writes:
>>>>> "Larry" == Larry Rosler <lr@hpl.hp.com> writes:
Larry> In article <81g8ul$dmv$1@nnrp1.deja.com> on Wed, 24 Nov 1999 08:51:33
Larry> GMT, Magnus Johansson <di5majo@my-deja.com> says...
>>> If I want to check if a text only contains characters a-z how should I
>>> do then?
Larry> Assuming the string is in $_:
Larry> Slower way:
Larry> /^[a-z]*\z/ and print "Yes.\n";
VM> ------------------------^
VM> At first I thought this was wrong, but I tested it and sure enough it
VM> works. I looked at perlre and nowhere did it say \z. \Z yes, but not
VM> \z. Where is this little pearl?
from perlre, 5.005_03 (edited):
Perl defines the following zero-width assertions:
\A Match only at beginning of string
\Z Match only at end of string, or before newline at the end
\z Match only at end of string
backspace rather than a word boundary.) The \A and \Z are
just like "^" and "$", except that they won't match multiple
times when the /m modifier is used, while "^" and "$" will
match at every internal line boundary. To match the actual
end of the string, not ignoring newline, you can use \z.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 24 Nov 1999 10:31:14 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: reg expr question
Message-Id: <slrn83o4sm.m2v.abigail@alexandra.delanet.com>
Larry Rosler (lr@hpl.hp.com) wrote on MMCCLXXVI September MCMXCIII in
<URL:news:MPG.12a59aa9da2231ae98a26f@nntp.hpl.hp.com>:
?? In article <81g8ul$dmv$1@nnrp1.deja.com> on Wed, 24 Nov 1999 08:51:33
?? GMT, Magnus Johansson <di5majo@my-deja.com> says...
?? > If I want to check if a text only contains characters a-z how should I
?? > do then?
??
?? Assuming the string is in $_:
??
?? Slower way:
??
?? /^[a-z]*\z/ and print "Yes.\n";
??
?? perldoc perlre
??
?? Faster way:
??
?? ! tr/a-z//c and print "Yes.\n";
??
The latter has to always process the entire string.
/[^a-z]/ or print "Yes.\n";
only needs to process the entire string on a yes; it would do an early
return on a failure.
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Wed, 24 Nov 1999 16:49:10 GMT
From: Samuel Kilchenmann <skilchen@swissonline.ch>
Subject: Re: sprintf help
Message-Id: <81h4u5$1b9$1@nnrp1.deja.com>
In article <slrn83nm2s.gfs.simon@othersideofthe.earth.li>,
simon@brecon.co.uk wrote:
> esalmon@packet.net (comp.lang.perl.misc):
> >How would I round up a scallar using the sprintf format?
> > $weight = 2.25
> > $rounded_up = sprintf("?????", $weight);
> >$weight should = 3
>
> perldoc -q round
>
> Makes you think the FAQ was written for a reason, doesn't it?
>
Please, please, please: Show me, how you do round up with sprintf or
anything else mentioned in the FAQ ...
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 24 Nov 1999 10:58:43 -0500
From: kevin montuori <montuori@acs.neu.edu>
Subject: Re: Test for eval() without using eval() ??
Message-Id: <yge3dtvq3t8.fsf@spot.acs.neu.edu>
>>> Jonathan Stowe writes:
js> I would agree that it probably is a -T supplied to perl from
js> some system (I'm thing of something like IIS ) that have a
js> central configuration for running scripts - indeed such a system
js> could well supply -MSafe for instance ...
-T all by itself isn't going to complain about eval() per se:
spot: perl -Te 'eval {print "hi there."}'
hi there.
a Safe compartment would, if the correct operators were
denied. i believe it would be difficult (and useless) to have
arbitrary CGI programs reval()ed within a Safe compartment
though.
either way, writing any nontrivial CGI program in perl without
using CGI.pm is a fool's errand. matt kruse's use of ancient
code like this [1]:
if ($ENV{'REQUEST_METHOD'} eq "GET")
{ $in = $ENV{'QUERY_STRING'};}
elsif ($ENV{'REQUEST_METHOD'} eq "POST")
{read(STDIN,$in,$ENV{'CONTENT_LENGTH'});}
isn't really providing anyone much of a service.
cheers,
k.
[1] http://www.mattkruse.com/scripts/calendar/download/calendar.tar
--
kevin montuori
interactive web services
northeastern university
------------------------------
Date: Wed, 24 Nov 1999 10:57:15 -0600
From: "Matt Kruse" <mkruse@rens.com>
Subject: Re: Test for eval() without using eval() ??
Message-Id: <81h55e$e2h$1@ffx2nh3.news.uu.net>
Tom Phoenix <rootbeer@redcat.com> wrote
> Without any dependencies AT ALL!
Your sarcasm is noted...
In case you did actually miss my point... My goal is to write the script so
that it runs on any OS, any web server, any version of perl 5, and without
using any modules that may or may not be on the machine. My target audience
is not perl experts, CGI experts, or people who read this newsgroup. It's
people who may not even understand CGI very well, but want to make a program
work with little or no modifications necessary. So far, I've been very
successful.
In some cases, the version of perl installed is not even 'standard'. Such is
the case with the complaints I've had about eval(). In these cases, I would
at least like to trap this situation and give a nice error message back. I'm
not going to support a version of perl that won't use eval() but I at least
want to detect it.
Now tell me, why is any of that bad?
Matt Kruse
mkruse@netexpress.net
http://www.mattkruse.com/
------------------------------
Date: Wed, 24 Nov 1999 11:07:23 -0600
From: "Matt Kruse" <mkruse@rens.com>
Subject: Re: Test for eval() without using eval() ??
Message-Id: <81h5oe$ejj$1@ffx2nh3.news.uu.net>
kevin montuori <montuori@acs.neu.edu> wrote
> either way, writing any nontrivial CGI program in perl without
> using CGI.pm is a fool's errand.
I've found that you cannot depend on CGI.pm being installed on a target web
server. Also, CGI.pm is huge and non-intuitive, IMO. I don't like it. And
no, I'm certainly not alone in this feeling. Don't even try to tell me that
everyone likes and uses CGI.pm.
> matt kruse's use of ancient
> code like this [1]:
> if ($ENV{'REQUEST_METHOD'} eq "GET")
> { $in = $ENV{'QUERY_STRING'};}
> elsif ($ENV{'REQUEST_METHOD'} eq "POST")
> {read(STDIN,$in,$ENV{'CONTENT_LENGTH'});}
> isn't really providing anyone much of a service.
This is older code, but it works just fine. I've never had a complaint.
Even so, I am going to look through CGI.pm to see if I can pull some "safer"
code from it to use. Although, I really wasn't asking for your opinion of my
programming style (I'm sorry if not everyone is as perfect of a perl
programmer as appear to be).
This set of replies to my original question has the been the most hostile
that I've ever experienced. It's no wonder people are afraid to ask
questions. If you make one mistake or ask something that people don't think
you should be asking, you get torn apart.
I don't think I'll respond to any more of this thread, as it has become
useless and nothing but an opportunity for all the holier-than-thou's of
this group to try to belittle someone who they don't think is doing
something in as perfect a way as they would do.
Matt Kruse
mkruse@netexpress.net
http://www.mattkruse.com/
------------------------------
Date: Wed, 24 Nov 1999 15:34:02 +0000
From: Jason <jason.holland@dial.pipex.com>
Subject: Tiny MacPerl Script
Message-Id: <383C056A.370EA9C3@dial.pipex.com>
Hello all,
Here's a tiny MacPerl script to get around an *annoying* problem when
deleting lots of files:
#!/usr/local/bin/perl -w
foreach ( @ARGV ) {
unlink( $_ );
}
One annoying problem with the MacOS is that if you do a Sherlock find
for some files to delete, if some of the files in the list have the same
name then you cannot simply do a "select all" -> "command-delete". The
Finder doesn't like to delete several files with the same name at the
same time.
This is a problem that's been bugging me for a while now.
This little script merely deletes the file at once, bypassing the Finder
completely. USE WITH CARE as the files CANNOT be pulled back out of the trash!
Bye!
jason.holland@dial.pipex.com
------------------------------
Date: Wed, 24 Nov 1999 15:50:13 +0000
From: Jason <jason.holland@dial.pipex.com>
Subject: Traversing Inheritance Tree
Message-Id: <383C0935.57B77CC5@dial.pipex.com>
Hello all,
I recently came across a little problem that I can't figure out.
I have a number of modules that use multiple inheritance, each of which
will have an initialisation method which will be called automagically by
the superclass's object constructor. Pretty much all of the classes
derive their object constructor from a single superclass.
The problem I have is that up until now only one class has had an
initialisation method, so it always gets called no matter what. However,
I now have two classes (one inheriting from the other), both of which
have an initialisation method which needs to be called; obviously the
sub-class is overriding the superclass's initialisation method.
Is there a simple way of calling all methods with a certain name in all
inherited classes, not to mention the inherited classes inherited
classes... ( My head hurts ;-) ).
I've already investigated page 115 (if I remember correctly) of the
"Advanced Perl Programming" book, and searching the current class's @ISA
is not a problem. But I also need to search the @ISA's of the inherited
classes and so on. I'm having trouble when it comes to accessing the
inherited class's @ISA array, I've got a feeling that an eval is needed somewhere.
I've starting to think that I'm going about this the wrong way...
Thanks in advance!
jason.holland@dial.pipex.com
------------------------------
Date: Wed, 24 Nov 1999 08:20:39 -0800
From: Jason Dreyer <jason.dreyerNOjaSPAM@home.com.invalid>
Subject: Re: using regex to extract data
Message-Id: <1415c574.4b838be5@usw-ex0101-001.remarq.com>
Thank you very much. That was the easy way. After you pointed me to
the correct module and gave some sample code, it was a snap.
* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
------------------------------
Date: Wed, 24 Nov 1999 08:27:53 -0800
From: Jason Dreyer <jason.dreyerNOjaSPAM@home.com.invalid>
Subject: Re: using regex to extract data
Message-Id: <1bd14d26.4d662bef@usw-ex0101-001.remarq.com>
In article <slrn83mdkn.ce6.tadmc@magna.metronet.com>,
tadmc@metronet.com (Tad McClellan) wrote:
> >Also, I have tried the following code.
> >if ($line =~ /Oct 14[^1999]/);
> ^^^^^^^
> That is exactly equivalent to [^91] you know...
> I don't think Character Classes work the way you think they do.
You are probably right. But you don't learn unless you try. Thanks
for pointing it out.
* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
------------------------------
Date: Wed, 24 Nov 1999 08:32:17 -0800
From: Jason Dreyer <jason.dreyerNOjaSPAM@home.com.invalid>
Subject: Re: using regex to extract data
Message-Id: <20c2f050.4e8c1a3f@usw-ex0101-001.remarq.com>
In article <O5L_3.529$6Y1.6324@nsw.nnrp.telstra.net>,
mgjv@comdyn.com.au (Martien Verbruggen) wrote:
> You could use the flipflop operator:
> my @d;
> while(<DATA>)
> {
> next unless (/^Date and Time: Thu Oct 14 08:12:00 1999/ .. 0);
> push @d, (/^Description\s+:\s(.+)$/);
> }
> read more about it in perlop:
> # perldoc perlop
This was a little bit over my head. I'll check out perlop and look
into it. Thanks.
* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
------------------------------
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 1478
**************************************