[13214] in Perl-Users-Digest
Perl-Users Digest, Issue: 624 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 23 19:15:30 1999
Date: Mon, 23 Aug 1999 16:10:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 23 Aug 1999 Volume: 9 Number: 624
Today's topics:
Re: Request for Comments: www.perl.com (Mark W. Schumann)
Re: Shamefully simple question. <jyoyoliu@hotmail.com>
Re: Shell vs Perl (Sam Holden)
Simple text rotating and gif98a generating perl script marcza@my-deja.com
Re: someone pleae help <jyoyoliu@hotmail.com>
Re: sorting files randomly out of a list <garethr@cre.canon.co.uk>
Re: sorting files randomly out of a list <cassell@mail.cor.epa.gov>
Re: sorting files randomly out of a list <cassell@mail.cor.epa.gov>
The scipt dont work.!!!help me <rcortes@alumnos.utfsm.cl>
Re: URGENT: Freelance perl coder required <jyoyoliu@hotmail.com>
Re: Why $|++ (was: Re: perl system()) (Neko)
Re: Why use Perl when we've got Python?! (Ilya Zakharevich)
Re: Why use Perl when we've got Python?! <garethr@cre.canon.co.uk>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 23 Aug 1999 17:09:17 -0400
From: catfood@apk.net (Mark W. Schumann)
Subject: Re: Request for Comments: www.perl.com
Message-Id: <7psd9t$k3q@junior.apk.net>
In article <7pkaou$9gu$1@nnrp1.deja.com>,
mike cardeiro <mikecard@my-deja.com> wrote:
>In article <37bc93cd@cs.colorado.edu>,
> tchrist@mox.perl.com (Tom Christiansen) wrote:
>> I would like to solicit from you answers to the following questions:
>> What you don't like at www.perl.com
>> --tom
>
>the biggest problem i've encountered is some (not all) of the
>documentation is not formatted to fit any screen...so you end up with
>that pesky little horizontal scroll bar at the bottom and have to scroll
>left to right for every line you read...YUCK
I must be misinterpreting this. If the documentation is "not formatted
to fit any screen," then surely the user agent (browser) can display it
in whatever way is easiest to read. And then _that_ is "designing for
the WWW."
Do you mean that the documentation _is_ formatted (in terms of line
widths) but not to a width you find reasonable? Otherwise I'm not
sure I get what you're saying.
------------------------------
Date: Mon, 23 Aug 1999 17:05:54 -0500
From: "James Liu" <jyoyoliu@hotmail.com>
Subject: Re: Shamefully simple question.
Message-Id: <lyjw3.195$UR5.42545@news.corecomm.net>
Hash: SHA1
You give a little, you get a little. I'm an extremely inexperienced
perl programer (have Llama, looking through Perl Unleashed, 21 Day &
Perl by Example). The simple solution is to write a page with a
javascript redirect script. Those are really simple to do, and you
can get it from anyone.
Thanks, and thanks to the a rest of you for helping me out.
<mrbog@my-deja.com> wrote in message
news:7ps16m$cv3$1@nnrp1.deja.com...
>
>
> Alright I'm ashamed to ask this, because I'm a somewhat experienced
> perl programmer, but I couldn't find this in the camel book (or the
> cookbook, or the advanced perl book, etc etc see I TOLD you I was
> fairly experienced!)
>
> All I want to do is, instead of a cgi constructing and returning a
> page to the user, I want it to push the user to a URL.
>
> That's it!
>
> Up to now whenever I'd need to do that, I'd like give them a page
> that either had a meta tag that pushed them where I wanted them to
> go, or I'd have something like <body
> onload="document.href='http:sfdsdf'">
>
> hehe! I'm so ashamed..
>
> -Mike
>
>
>
> Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
Version: PGPfreeware 6.5.1 for non-commercial use <http://www.pgp.com>
iQA/AwUBN8HFwRlrzTx6g1omEQLKRwCfVuRL/XgZJ0QQ/EiNDVhyvyUFS74AoMnk
UqskZJdTbIBXX2UdH2pRvkrZ
=3qXL
-----END PGP SIGNATURE-----
------------------------------
Date: 23 Aug 1999 22:26:03 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Shell vs Perl
Message-Id: <slrn7s3iku.g9p.sholden@pgrad.cs.usyd.edu.au>
On Mon, 23 Aug 1999 11:06:21 -0400, Ala Qumsieh <aqumsieh@matrox.com> wrote:
>
>kcounts@my-deja.com writes:
>
>> !#/usr/bin/ksh
>>
>> if [ "$1" = "" ]
>> then sort -t: +2n -3 /etc/passwd
>> else
>> grep "[:/]$1[:/]" /etc/passwd | sort -t: +2n -3
>> fi
>>
>>
>> He says it took him a page and a half in Perl.
>> I know it can be more efficient.
>
>#!/usr/bin/perl -w
>
>if (@ARGV) {
> system qq!grep "[:/]$ARGV[0]\[:/]" /etc/passwd | sort -t: +2n -3!;
>} else {
> system qq!sort -t: +2n -3 /etc/passwd!;
>}
Or even...
#!/usr/local/bin/perl -w
open (STDOUT, "|sort -t: +2n -3") || die "Unable to fork a shell???: $!";
open (PASS, "/etc/passwd") || die "Unable to open /etc/passwd for reading: $!";
$ARGV[0] = '.?' unless @ARGV;
while(<PASS>) {
print if m|[:/]$(?:ARGV[0])[:/]|o;
}
close(STDOUT) || die "Couldn't close the sort???: $!"
A little longer than the ksh version but not by much. Running shell commands
is not considered a bad thing in perl. Why write your own sort when one
already exists.
Note: that the functionality is a little different. The argument is now a perl
regex fragment, and so is more powerful than the lowly regexes of grep...
Also any lines which only have a single (or none at all) : won't be printed
in the no argument form.
I guess you could write your own sort routine for perl... Assuming the sort
command sorts based on the UID field in numerical order - I'm not a sort guru,
and my man page says that usage is obsolete (and describes a slightly different
usage of the form +w.xT -y.zU.
#!/usr/local/bin/perl -w
open(PASS,"/etc/passwd") || die "Unable to open /etc/passwd for reading: $!";
$ARGV[0] = '.*' unless @ARGV;
print map {$_->[1]} sort {$a->[0] <=> $b->[0]} map {[(split /:/,$_,4)[2],$_]}
grep /[:\/](?:$ARGV[0])[:\/]/o, <PASS>;
There you go it is shall we say a fraction shorter than a page and a half.
--
Sam
Remember that the P in Perl stands for Practical. The P in Python
doesn't seem to stand for anything.
--Randal Schwartz in <8cemsabtef.fsf@gadget.cscaper.com>
------------------------------
Date: Mon, 23 Aug 1999 22:34:49 GMT
From: marcza@my-deja.com
Subject: Simple text rotating and gif98a generating perl script ??
Message-Id: <7psia8$qjc$1@nnrp1.deja.com>
As you might know HTML + Javascript don't offer a feature
to write text vertical (from bottom to top).
So what should I do if I often need text 90 degrees clockwise rotated ?
The text itself depends from user entries and is unpredictable.
Well I don't want java because the potential users might have disable
their browser java capability. Moreover java is slow...
One way could be
to use an external graphic program,
call this program from perl (cgi) script with the desired text through
an appropriate API,
let the program rotate this text
produce a transparent gif file
and finally take this gif file and insert it into the original html
code.
Beside the fact that I don't know a graphic program that let me
do such things through an API, I fear that this could be a fat program
like photoshop - This is unacceptable due to performance problems.
So my last hope is a perl script which could do the job.
In general perl can generate image file. Example (ignore line wraps):
print "Content-type:
image/gif\n\nGIF89a\1\0\1\0\200\0\0\0\0\0\0\0\0!\371\4\1\0\0\0\0,\0\0\0
\0\1\0\1\0\0\2\2D\1\0\n";
Does anyboday know a script which let me do the task mentioned above ?
Thanx
Marcus
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Mon, 23 Aug 1999 17:11:38 -0500
From: "James Liu" <jyoyoliu@hotmail.com>
Subject: Re: someone pleae help
Message-Id: <IDjw3.198$UR5.42576@news.corecomm.net>
Hash: SHA1
why don't you try to extract the stuff between the <tr> </tr> tags.
check the faq. i'm sure you can find some regular expression to let
you do that.
Carlos Cerna <cerna@cig.mot.com> wrote in message
news:37BA9B4F.FC0C00D9@cig.mot.com...
> Guys I have never wrote a perl script I know a bit about html.My
> problem is that I need a script that would read a html page that
> contains a table (html generated) and allow me to change 6 text
> fields and write the changes back to the file.While on line,of
> course the script need to generate a form and ask the user to enter
> the page to be updated/change eg:1d.html.Then have 6 text fields to
> change.
>
Any help would greatly be appreciated.
Version: PGPfreeware 6.5.1 for non-commercial use <http://www.pgp.com>
iQA/AwUBN8HHGRlrzTx6g1omEQISKQCgqI7lQDDjjn4It0CIBRln7vSeHWYAoOyR
vjcKGiwrr4qQfeufT6j25Cv3
=Q3OM
-----END PGP SIGNATURE-----
------------------------------
Date: Mon, 23 Aug 1999 21:14:01 GMT
From: Gareth Rees <garethr@cre.canon.co.uk>
Subject: Re: sorting files randomly out of a list
Message-Id: <silnb2w67a.fsf@cre.canon.co.uk>
mmilovan@grolier.fr wrote:
> I'm trying to pick 30 files randomly from a list of 100 files.
After defining
# permutation(k,n) is a random permutation of k elements from 0..n-1.
sub permutation {
my ($k, $n) = @_;
0 <= $k and $k <= $n or die "k=$k, n=$n does not satisfy 0<=k<=n";
my @p = (0 .. $n - 1);
my $i = $k;
while ($i-- > 0) {
my $j = int rand $n--;
@p[$n,$j] = @p[$j,$n];
}
return @p[-$k .. -1];
}
# combination(k,n) is a random combination of k elements from 0..n-1.
sub combination { sort { $a <=> $b} permutation(@_) }
you can write an expression like
@files[combination(30, scalar @files)]
to get a list of 30 random files from @files.
Aside: is there a way to avoid the sort when computing the combination?
In other words, is there an O(k) algorithm for generating a combination
of k elements from 0..n-1?
--
Gareth Rees
------------------------------
Date: Mon, 23 Aug 1999 15:35:02 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: sorting files randomly out of a list
Message-Id: <37C1CC96.61B6F5AA@mail.cor.epa.gov>
m m m wrote:
>
> Hi everyone
> I'm trying to find a way to pick up say 30 different files randomly out of
> the same list/table containing 100 files.
> these 30 files should be different everytime I try to access them.
> is there an easy way to do that?
> thanks
Sure. Put your filenames in an array. Use rand() to pick
out an index from your array. Do this 30 times. I would
suggest using map() for the iteration.
Code for this has been shown in this newsgroup, so you can
go to deja.com and search for it if you don't want to write
it yourself.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 23 Aug 1999 15:40:12 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: sorting files randomly out of a list
Message-Id: <37C1CDCC.6C4C328@mail.cor.epa.gov>
Gareth Rees wrote:
>
> mmilovan@grolier.fr wrote:
> > I'm trying to pick 30 files randomly from a list of 100 files.
>
> After defining
>
> # permutation(k,n) is a random permutation of k elements from 0..n-1.
> sub permutation {
> my ($k, $n) = @_;
> 0 <= $k and $k <= $n or die "k=$k, n=$n does not satisfy 0<=k<=n";
> my @p = (0 .. $n - 1);
> my $i = $k;
> while ($i-- > 0) {
> my $j = int rand $n--;
> @p[$n,$j] = @p[$j,$n];
> }
> return @p[-$k .. -1];
> }
>
> # combination(k,n) is a random combination of k elements from 0..n-1.
> sub combination { sort { $a <=> $b} permutation(@_) }
>
> you can write an expression like
>
> @files[combination(30, scalar @files)]
>
> to get a list of 30 random files from @files.
>
> Aside: is there a way to avoid the sort when computing the combination?
> In other words, is there an O(k) algorithm for generating a combination
> of k elements from 0..n-1?
When this came up before [oh, a couple months ago], Larry
Rosler suggested the equivalent of:
my $max = @array<10 ? @array : 10;
my @selected = @array;
@selected = map splice (@selected,rand @selected, 1), 1..$max;
just in case you were interested,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 23 Aug 1999 06:19:19 -0400
From: Rodrigo =?iso-8859-1?Q?Cort=E9s?= <rcortes@alumnos.utfsm.cl>
Subject: The scipt dont work.!!!help me
Message-Id: <37C12027.93FCD80D@alumnos.utfsm.cl>
I recently write a script in perl. In my computer it work perfectly but
when i try to execute it in the server (virtualave.net) does'nt work.
------------------------------
Date: Mon, 23 Aug 1999 17:32:53 -0500
From: "James Liu" <jyoyoliu@hotmail.com>
Subject: Re: URGENT: Freelance perl coder required
Message-Id: <FXjw3.201$UR5.43451@news.corecomm.net>
Hash: SHA1
as a matter of fact, i'm doing both. i have one for B, and i'm
working on A. I'll e-mail you w/ a.
Tony Dillon <tonyd@kellion.demon.co.uk> wrote in message
news:935308579.5212.0.nnrp-12.9e987314@news.demon.co.uk...
> I have a couple of small Perl scripts I need written immediately.
> Nothing too complicated, but tight deadlines mean that I don't have
> the time to write them myself.
>
> I need:
>
> a) A script to parse a CSV file into a table. The CSV is located on
> another server. b) A script to create a straight HTML menu of text
> files in a folder, using the first line of each file to create the
> menu headings, and then generate a HTML page using the se;ected
> text file.
>
> For more info, please contact me direct at either:
>
> tdillon@tdmultimedia.com
>
> or
>
> tony@tonydillon.com
>
>
>
Version: PGPfreeware 6.5.1 for non-commercial use <http://www.pgp.com>
iQA/AwUBN8HMExlrzTx6g1omEQLfqACgl4MfgmlE99vLmXItknIgEfKYA8QAoNV+
3qJcUfvvyuvClTP0+6r3rIQv
=7fCl
-----END PGP SIGNATURE-----
------------------------------
Date: Mon, 23 Aug 1999 22:48:06 GMT
From: tgy@chocobo.org (Neko)
Subject: Re: Why $|++ (was: Re: perl system())
Message-Id: <37c19b6e.54938375@news.supernews.com>
I don't have Abigail's reply here, so I'm going to use David's instead.
On Sun, 22 Aug 1999 15:56:57 -0700, David Cassell <cassell@mail.cor.epa.gov>
wrote:
>Abigail wrote:
>[big snip]
>> "Because Randal did it" isn't an excuse. "Because <whoever> did it" is
>> never an excuse. Never, ever use code you cannot explain. Else, you'll
>> be cargo cult programming.
[snip David jumping off a bridge]
I was not using Randal's column or his name as an excuse, nor do I believe
using '$|++' instead of '$| = 1' warrants one. They both accomplish the same
task. Speed is not an issue. That $| may be -1 is not an argument I would
champion (code consistently and consistently unbuffer using either '$| = -1',
'$| = 1', '$|++' or something else). Obscure? I thought the same when I
first saw you use map() in a void context -- I know that wasn't your intent.
As for an explanation, I actually find '$|++' easier to read. To me, it
parses as one word whereas '$| = 1' parses as three. And if I started to use
'$| = 1', next thing you know, someone's going to tell me I'm being obscure
and that I should really be using 'FH->autoflush' instead. :)
--
Neko | tgy@chocobo.org | Will hack Perl for a moogle stuffy! =^.^=
------------------------------
Date: 23 Aug 1999 20:15:29 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Why use Perl when we've got Python?!
Message-Id: <7psa51$5fb$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Abigail
<abigail@delanet.com>],
who wrote in article <slrn7s1l29.jkg.abigail@alexandra.delanet.com>:
> __ > What of course really sucks in Perl is that you cannot easily do operator
> __ > overloading, unless you resort to 'use overload'. Which of course, doesn't
> __ > have overload magic for assignment or indexing.
> __
> __ Of course, you did not do
> __
> __ perldoc overload
> __
> __ for loooooooooooooong time.
>
>
> $ man overload
> ....
> However, it does not overload the Perl
> assignment operator. This would go against Camel hair.
Aha, and you cannot read *your own posts* either... ;-)
> __ Aha, and you do not read p5p either...
>
>
> I'm not interested in discussion forums that turn into moderated ones
> just because someone has the technical means, and not the concensus.
One can hardly argue with this...
But people who do not read p5p do not know about this unfortunate
event. ;-)
Ilya
------------------------------
Date: Mon, 23 Aug 1999 21:33:32 GMT
From: Gareth Rees <garethr@cre.canon.co.uk>
Subject: Re: Why use Perl when we've got Python?!
Message-Id: <siemguw5ar.fsf@cre.canon.co.uk>
xah@weborder.com wrote:
> The ivy tower class of buttheads insist on symbolism for math,
> clinging to the fancy that certain ideas are better expressed in
> certain language. They created a whole barrier of entry [...]
>
> [...] If someone cannot read my code, it is their shortcoming.
Can you spot the contradiction?
--
Gareth Rees
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
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" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. 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" from
almanac@ruby.oce.orst.edu.
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 624
*************************************