[9665] in Perl-Users-Digest
Perl-Users Digest, Issue: 3259 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 26 23:17:41 1998
Date: Sun, 26 Jul 98 20:01:16 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 26 Jul 1998 Volume: 8 Number: 3259
Today's topics:
Re: Building and sorting a list of records (Andrew M. Langmead)
Re: Coding Quiz (was Re: efficiency: print<<"xxx" vs. p (Peter "Shaggy" Haywood)
Re: Criation de formulaire ? <kenner@DELETE.MExnet.com>
Re: Dynamically creating graph images <efinch@cais.com>
Re: Gif Image Questions (Gael Marziou)
Re: How to put mailbox contents on HTML? (-)
perl and binary data file (Jingfang Wang)
Re: Problem with 'use strict' pragma (Martien Verbruggen)
Problem with piped output on Win98 <pkeefe@ix.netcom.com>
Re: program used to pass switches Garp
Re: Reacting to 1 of 10 or so possible values.... Need (Andre L.)
Re: Reacting to 1 of 10 or so possible values.... Need <metcher@spider.herston.uq.edu.au>
Re: Reacting to 1 of 10 or so possible values.... Need <jwb79@mail.idt.net>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 27 Jul 1998 00:49:46 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Building and sorting a list of records
Message-Id: <EwqAAy.J2E@world.std.com>
"Stephane Barizien" <sto41@wanadoo.fr> writes:
>I want to build a list of records in a loop, then sort that list according
>to a given field.
>push @lines, (field1 => $somevalue, field2 => $anothervalue);
This pushes four elements to the array @lines. I don't think that is
what you want. You also never store the line itself anywhere, but you
may not need that (you may only want the two records and recreat the
line from there.) It seems that you either need to create parallel
arrays for each element or a multidimentional array.
The multidimentional one would look like this:
while(<>) {
# break the lines into fields here.
# ...
push @lines { field1 => $somevalue, field2 => $anothervalue };
}
@sortedlines = sort byfield2 @lines;
sub byfield2 {
$a->{field2} cmp $b->{field2}
}
But since each element of @line is a reference to a hash, when you
print it out, you have to access it with a dereferencing operator:
for $line (@sortedlines) {
print "$line->{field1} $line->{field2}\n";
}
For details on multidimentional arrays, check the perlref, perllol and
perldsc man pages.
The parallel array one would look like this:
while(<>) {
# break line into fields here
# ...
push @field1, $somevalue;
push @field2, $anothervalue;
}
sub byfield2 {
$field2[$a] cmp $field2[$b];
}
@indicies = sort byfield2 0 .. $#field2;
@sortedfield1 = @field1[@indicies];
@sortedfield2 = @field2[@indicies];
If you store the entire line as well as fields 1 and 2, you can reduce
the last three lines to:
@sortedlines = @lines[ sort byfield2 0 .. $#lines ];
There is some information about sorting that you might like to look at
on <URL:http://www.perl.com/CPAN/doc/manual/html/pod/perlfaq4/
How_do_I_sort_an_aray_by_anyth.html>
--
Andrew Langmead
------------------------------
Date: Thu, 23 Jul 1998 15:49:36 GMT
From: phaywood@aardvark.apana.org.au.STOP.SPAM (Peter "Shaggy" Haywood)
Subject: Re: Coding Quiz (was Re: efficiency: print<<"xxx" vs. print)
Message-Id: <35b48187.2540500@news.aardvark.apana.org.au>
Groovy hepcat Uri Guttman was jivin' on 17 Jul 1998 00:27:01 -0400 in
comp.programming.
Coding Quiz (was Re: efficiency: print<<"xxx" vs. print)'s a cool
scene! Dig it!
>
>this thread has inspired me to post a short quiz i created may years
>ago. the last time i posted it (comp.lang.c, and others) a few years
>ago, it caused quite a flame war.
So naturally you decided to repost it here.
>1. Who is main the PERSON you should think about while you are writing code?
Ralph Wiggum. The next person to look at my code could be a total
moron like him. (And I do not mean me!)
>2. Other than comments, what is the most important HUMAN aspect of code?
Visual structure, so I can find what I'm looking for and remember
what a function does in code that's months old (or even minutes old).
>3. What is the main PURPOSE of comments?
See answer to Q 2 above.
>Bonus: What is the OPPOSITE of spaghetti code?
Meatball code? I don't know. Steak & 3 veg code? I've got it!
Structured code... with mashed potatoes & gravy. :)
--
----- Dig the EVEN NEWER, MORE IMPROVED news sig!! -----
-------------- Shaggy was here! ---------------
http://aardvark.apana.org.au/~phaywood/
============= Ain't I'm a dawg!! ==============
------------------------------
Date: Sun, 26 Jul 1998 17:21:36 -0500
From: "Kenner" <kenner@DELETE.MExnet.com>
Subject: Re: Criation de formulaire ?
Message-Id: <6pgfvk$nf8$1@flood.xnet.com>
[courtesy cc of this posting sent to cited author via email]
Je pensais que je vous dirais plusieurs choses qui vous aideront (j'esphre).
Je ne suis pas francophone, mais j'ai decidi d'essayer - je m'excuse si mon
frangais est ipouvantable.
Les gens ici n'aime pas quand quelqu'un affiche quelque chose qui n'est pas
en anglais. C'est seulement parce que la plupart de gens qui vient ici est
anglophone. Ce n'est pas parce que les gens pensent que anglais est
meillure, c'est ` cause du fait qu'ils ne parlent pas frangais! Alors, pour
recevoir plus d'assistance (ici), icrivez en anglais.
La deuxihme chose est que votre question n'est pas en relation avec Perl.
Ce groupe existe seulement pour assister les gens qui icrit des programmes.
Il y a beaucoup de pages sur le WWW qui offre beaucoup de scripts CGI sans
co{t - utilise Yahoo (www.yahoo.com) pour les trouver. Aussi allez `
www.perl.com et www.perl.com/CPAN/ - si vous voulez apprendre Perl, ces sont
les ressources inestimables (est il y a quelques scripts l` pour regarder et
utiliser, aussi). Mais, vous pouvez faire ce que vous voulez faire avec
plusiers langues, pas seulement Perl. @ cause de ga, c'est probablement
meillure pour vous que la plupart des gens ici ne pouvait pas lire votre
lettre, parce qu'ils *detestent* les gens qui afficher des questions
impropres ou qui demander scripts (ils l'appelent "gimme" - anglais pour
"donne-moi"), et plusieurs d'eux sont trhs grossiers avec leur reponses.
Bonne chance, est j'esphre que vous trouvez ce que vous cherchez!
--
Kenner
# If you want to send me e-mail, please remove the "DELETE.ME" from my
address. #
"I'm glad that I could help out my friend Stephen with his art." - Stuart
Davis
------------------------------
Date: Sun, 26 Jul 1998 22:17:40 -0400
From: Ed Finch <efinch@cais.com>
Subject: Re: Dynamically creating graph images
Message-Id: <35BBE344.67875F88@cais.com>
Joseph M Carlton wrote:
> I am using perl to fetch data from a database for a web project that I am
> working on. Now, I need to dynamically build a bar graph with this data.
> Someone told me that I could use javascript and somebody told me that I
> could do the whole thing in perl. I have not been able to find any
> information on this topic for either javascript or perl. Could someone
> PLEASE direct me to a book or web page with information on this? I am
> not limited to perl and javascript, so if anyone knows of a better way to
> do this. I would be VERY appreciative. Thanks in advance for your help.
ClGraph and SARGE both do this; see http://www.vais.net/~efinch
Regards,
Ed
Q: Why do PCs have a reset button on the front?
A: Because they are expected to run Microsoft operating systems.
------------------------------
Date: Sun, 26 Jul 1998 22:43:16 GMT
From: gmarziou@club-internet.fr (Gael Marziou)
Subject: Re: Gif Image Questions
Message-Id: <35bba99e.3819478@news.club-internet.fr>
To determine dimension of a GIF image, I use Image::Size module.
Gael
------------------------------
Date: Mon, 27 Jul 1998 02:43:34 GMT
From: root.noharvest.\@not_even\here.com (-)
Subject: Re: How to put mailbox contents on HTML?
Message-Id: <35bbe8f2.72560884@news2.cais.com>
"Bahram Pourghadiri" <bahram@netcomuk.co.uk> Said this:
>Is it possible to write a cgi to check a mailbox every 5 minutes say, and
>display the contents (with a little bit of formatting) on a pre-specified
>HTML page?
>
It would be easier to use a .forward file in the user's home
directory, which instructs the MTA (the Mail Transfer Agent, or
sendmail) to pipe the message to a script instead of writing it to the
mail spool file. Then you can have that script place the message
however you like. The simplest thing would be to use hypermail, but
that would just create an "archive" type interface rather than a real
HTML based client.
------------------------------
Date: 26 Jul 1998 23:50:53 GMT
From: jwang2@osf1.gmu.edu (Jingfang Wang)
Subject: perl and binary data file
Message-Id: <6pgfct$tps@portal.gmu.edu>
Can any one tell me whether Perl can read binary data file? And I also want
to know what is the most efficient way for Perl to read in a data file? How
about use Perl to read a data file comparing with using C or Fortran?
Thank you very much if you can tell me something about that. My email address
is: jwang2@gmu.edu
Thanks.
Jingfang
------------------------------
Date: 27 Jul 1998 02:26:48 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Problem with 'use strict' pragma
Message-Id: <6pgoh8$k36$1@nswpull.telstra.net>
In article <35B82868.348A@hotkey.net.au>,
Stephan Carydakis <steph@hotkey.net.au> writes:
> Hello all,
>
> I have written a search engine for a customer
> (http://www.yooralla.com.au/search.htm). I installed the script, and on
> the first run, it returned an error - "can't locate vars.pm in @INC". I
> rang the prescence provider and found that vars.pm was non existent,
> even though they assured me they were running Perl 5.something.
There are many, many differences between the 5.x versions. Even though
there are many zeroes and subversions, they are all very important.
5.001 is something completely different from 5.004_04.
> They copied vars.pm over to the server that my cutomers site lives on
ouch. That is NOT the way to go about it. What they really should do
is check what version they are really running, and 5.something is not
specific enough. If the version they are running is NOT 5.004_04, they
should upgrade. If it is, they should reinstall.
> from another installation of the same version of Perl(they reckon!!!).
If they have a perl installation that didn't have vars.pm installed,
but they 'reckon' that they can copy it from some other installation,
then I would doubt very seriously that they know what they are talking
about.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: Sat, 25 Jul 1998 18:24:42 -0400
From: "Pete Keefe" <pkeefe@ix.netcom.com>
Subject: Problem with piped output on Win98
Message-Id: <6pgaav$ji0@dfw-ixnews4.ix.netcom.com>
I hope someone can explain why:
1. the following code hangs at the second piped output call?
2. during the first call, access is made to the A: drive - yet there is
nothing in path to that drive?
I am running Gurusamy Sarathy 's outstanding port of 5.004_02 on Windows98.
open(FI1,"dir |") or die "at spawn 1: $!";
while(<FI1>) {
print;
}
close FI1;
print "First completed\n";
open(FI2,"dir |") or die "at spawn 2: $!";
while(<FI2>) {
print;
}
close FI2;
print "Second completed\n";
Thanks for any help,
Pete Keefe
------------------------------
Date: Sun, 26 Jul 1998 22:16:38 GMT
From: Garp
Subject: Re: program used to pass switches
Message-Id: <35bbaa5b.43250081@news.demon.co.uk>
On Sun, 26 Jul 1998 20:07:25 GMT, mcafee@stargate.rs.itd.umich.edu
(Sean McAfee) wrote:
>In article <35bb81dc.32881781@news.demon.co.uk>,
> <garp@syb7aris.demon.co.uk.with.no.7> wrote:
>>I don't have the Camel (haven't needed it yet) so I'm probably missing
>>context, but I'm interested as to why you'd want to stop switch
>>processing after '--' - is this common?
>
>Yes, it's a Unix convention, observed by many (but not all) commands, as
>well as the getopt() library function. Without it, it's difficult to deal
>with arguments that begin with a hyphen, as they'll be interpreted as
>switches. For instance, to remove a file called "-hyphen", you have to
>say "rm -- -hyphen".
>
>--
Right you are. How useful!
Cheers,
Garp
------------------------------
Date: Sun, 26 Jul 1998 17:43:41 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Reacting to 1 of 10 or so possible values.... Need some streamlining help.
Message-Id: <alecler-2607981743410001@dialup-804.hip.cam.org>
In article <35ba8c11.949828@enews.newsguy.com>, bulldog@usmc.net (BullDog
USMC) wrote:
> Hello.
>
> I have a script that accepts <so far> about 10 different 'request
> types'.
>
> Right now, I am handling this by doing the clumsy:
>
> if ($reqType eq "typeOne"){
> ...set up environment...
> ...execute routine(s)...
> exit;
> }
>
> if ($reqType eq "typeTwo"){
> ...set up environment...
> ...execute routine(s)...
> exit;
> }
You can emulate a Pascal-like case statement:
CASE:
foreach ($reqType) {
/^typeOne$/ && do {
...set up environment...
...execute routine(s)...
last CASE;
}
/^typeTwo$/ && do {
...set up environment...
...execute routine(s)...
last CASE;
}
# otherwise:
... handle any other values here ...
}
A.L.
------------------------------
Date: Mon, 27 Jul 1998 11:13:32 +1000
From: Jaime Metcher <metcher@spider.herston.uq.edu.au>
Subject: Re: Reacting to 1 of 10 or so possible values.... Need some streamlining help.
Message-Id: <35BBD43C.7F5A9B72@spider.herston.uq.edu.au>
Genuine, non-sarcastic question: I can see that this is more perlish,
but why is it more streamlined? For only ten possibilities, if all
equally likely, the original version is doing an average of five tests
per run. Is it really better to build a dispatch (despatch?) table for
this?
--
Jaime Metcher
M.J.T. Guy wrote:
>
> A Perlish way of doing this sort of thing is to use a hash as a dispatch
> table:
>
> my %actions = ( typeOne => \&process_type_one,
> typeTwo => \&process_type_two,
> ...
> );
>
> sub process_type_one { ... }
>
> sub process_type_two { ... }
>
> if (exists $actions{$reqType}) {
> $actions{$reqType}->();
> } else {
> die "Unknown request type `$reqType'\n";
> }
>
> Mike Guy
------------------------------
Date: 27 Jul 1998 02:57:35 GMT
From: "Jim Babbington" <jwb79@mail.idt.net>
Subject: Re: Reacting to 1 of 10 or so possible values.... Need some streamlining help.
Message-Id: <01bdb909$3abe82d0$6488fdc7@dixon>
Try using sub's:
/#!/usr/bin/perl -w
<get $reqType value here>
defined(&$reqType) or die "sorry, cant handle $reqType, yet"; # check for valid sub
&$reqType; # do the sub routine of the value in $reqType
sub typeOne {
<Fancy perl code here>
}
sub typeSeventyThree {
<more usefull code here>
}
I hope this helps,
jim
--
BullDog USMC <bulldog@usmc.net> wrote in article <35ba8c11.949828@enews.newsguy.com>...
: Hello.
:
: I have a script that accepts <so far> about 10 different 'request
: types'.
:
: Right now, I am handling this by doing the clumsy:
:
: if ($reqType eq "typeOne"){
: ...set up environment...
: ...execute routine(s)...
: exit;
: }
:
: if ($reqType eq "typeTwo"){
: ...set up environment...
: ...execute routine(s)...
: exit;
: }
:
: Et cetera...
:
: The problem is that each IF statement is getting more and more
: complex.
:
: Are there any suggestions on how to streamline this handling?
:
:
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 3259
**************************************