[15568] in Perl-Users-Digest
Perl-Users Digest, Issue: 2981 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 8 18:10:42 2000
Date: Mon, 8 May 2000 15:10:27 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <957823827-v9-i2981@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 8 May 2000 Volume: 9 Number: 2981
Today's topics:
Re: making a package (NOT a module) (Tad McClellan)
Re: Making my script not case-sensitive! <lr@hpl.hp.com>
Re: more regexp madness extracting data from files. <nospam@devnull.com>
Re: Need LWP module, but it's not installed on my serve <aqumsieh@hyperchip.com>
Re: Need LWP module, but it's not installed on my serve (Tad McClellan)
Re: Need LWP module, but it's not installed on my serve <kerry@shetline.com>
Re: Need LWP module, but it's not installed on my serve <nospam@devnull.com>
Newbie Relief!! perl_primer rel 0.99 (pUrl was taken :) john@thinman.com
Re: Newbie Relief!! perl_primer rel 0.99 (pUrl was take <andrew.mcguire@walgreens.com>
Re: Newbie Relief!! URL is http://puny.vm.com/perl_prim <john@thinman.com>
Re: Newbie Relief: http://puny.vm.com/perl_primer john@thinman.com
Perl code to check for broken links <erick.jensen@unisys.com>
Perl with VRML (Bob4dummys)
Please check my 'random' code <ra_jones@my-deja.com>
Re: Printing Arrays <jamalone@earthlink.net>
Re: Printing Arrays <tony_curtis32@yahoo.com>
Re: Printing Arrays <jamalone@earthlink.net>
Re: problems with $/ = "\r\n" (Windows text files and $ <psrchisholm@my-deja.com>
Re: program that prints itself (Mark-Jason Dominus)
Re: program that prints itself (Mark-Jason Dominus)
Programmer Required <Rob@barbados.cc>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 8 May 2000 16:40:20 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: making a package (NOT a module)
Message-Id: <slrn8he9hk.dia.tadmc@magna.metronet.com>
On Mon, 08 May 2000 17:37:59 GMT, sirena_b@my-deja.com <sirena_b@my-deja.com> wrote:
>I thought a package was for
>calling one script from another, but apparently
>not.
a "package" is nothing more than a "namespace".
A "namespace" (and hence packages) have nothing to do
with "calling one script from another".
They _do_ have to do with calling _functions_ in one file
from a program in another file though.
For executing external programs (whether written in Perl or not),
see
perldoc -q STDERR
for a review of 3 ways of running external programs.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 8 May 2000 12:25:40 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Making my script not case-sensitive!
Message-Id: <MPG.1380b48f9257738d98aa20@nntp.hpl.hp.com>
In article <391449B8.2E8D2369@tele.ntnu.no> on Sat, 06 May 2000 18:35:04
+0200, Ola Jetlund <jetlund@tele.ntnu.no> says...
> Tony Curtis wrote:
...
> > If you post code you need help/advice with, please post
> > *real* code otherwise people have to guess what you're
> > really trying to do, and the bits you snip usually turn
> > out to be where the problem lies :-)
> >
> > hth
> > t
>
> Okay I'm sorry - but here is the a code bit that works:
All right then. You are entitled to an answer.
> #!/usr/bin/perl
Get into the habit of using the '-w' flag and the 'use strict;' pragma
on *all* Perl code that you right. It will force you to think more
clearly about what you are doing, and eliminate potential bugs early in
the coding process. Do this and you will never regret it.
> opendir THISDIR, "." or die "Error: $!";
> @filer = readdir THISDIR;
> closedir THISDIR;
> @sfiles = sort(@filer);
You don't really need both of those arrays, which will contain multiple
copies of the file list. In fact, you can do what you want with no
copies. See below.
> $for0 = "ola";
> $ett0 = "jetlund";
> $hel0 = "ola_jetlund";
> $i = 0;
> print "\n";
> foreach(@sfiles){
foreach (sort readdir THISDIR) {
> if(($_ =~ $for0) and ($_ =~ $ett0))
That is a very poor way of expressing what you want.
if (/$for0/ && /$ett0/)
If the 'variables' won't change during execution of the program, you can
improve the performance by appending the /o modifier to each of the
regexes.
> {
> $i = $i + 1;
++$i;
> print "mv $_ ";
You are setting up a file of 'mv' commands. It would undoubtedly be
much more efficient to use the Perl builtin 'rename' function. See
below.
> printf ".ok/%s", $hel0 ;
Why the extra statement, and an unnecessary printf at that. Concatenate
to the previous print statement.
> if($i < 10)
> {
> printf "_00%1.0f", $i;
> }
> if(($i > 9) and ($i < 100))
> {
> printf "_0%2.0f", $i;
> }
This is a peculiar misuse of floating-point conversion. You seem to
want a two-digit number, padded with a leading zero if it is less than
10. There is an integer format specifier designed for that.
Replace all of the above by
printf '_0%.2d', $i;
> print ".trt\n";
> }
In fact, your print statements can all be reduced to this:
printf "mv $_ .ok/${hel0}_%.3d.trt\n", $i;
> }exit 0;
So the while loop can be written this way:
foreach (sort readdir THISDIR) {
if (/$for0/o && /$ett0/o) {
printf "mv $_ .ok/${hel0}_%.3d.trt\n", ++$i;
}
}
> So my problem now is what if a filename contains "Ola" and "Jetlund" and
> I want to rename this file in the same way to "ola_jetlund_###.trt" ?
So you just have to make a case-independent match, using the /i modifer
to each of the regexes.
Now for the graduate-level Perl way (UNTESTED). This uses magic auto-
incrementing to provide the padded integer, and rename() to rename the
files.
my $i = '000';
rename $_, ".ok/${hel0}_" . ++$i . '.trt' or
die "rename $_ failed. $!\n"
for sort grep /$for0/io && /$ett0/io => readdir THISDIR;
Read these docs for more details:
perldoc -f rename
perldoc -f grep
perldoc perlre
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 8 May 2000 21:28:58 GMT
From: The WebDragon <nospam@devnull.com>
Subject: Re: more regexp madness extracting data from files.
Message-Id: <8f7biq$1a9$1@216.155.32.56>
In article <slrn8hdd7o.cem.tadmc@magna.metronet.com>,
tadmc@metronet.com (Tad McClellan) wrote:
| >6 files (text/html) that all contain a large block of data of the form:
| >
| >the list of files to be checked will be stored in @inputFiles
| >
| >
| >maps[i++] = new Map("albundyvp","AlBundyVP",1350,"-1",-1);
| >maps[i++] = new Map("alienspt1vp","AlienSPT1VP",3257,"-1",-1);
| >maps[i++] = new Map("alornmappack","AlornMappack",1956,"-1",-1);
| >maps[i++] = new Map("amwaf","AMWAF",22,"-1",-1);
| >maps[i++] = new Map("austinpowersvp","AustinPowersVP",1033,"-1",-1);
| >maps[i++] = new Map("b2chosenvp","Blood2-ChosenVP",6219,"-1",-1);
| >maps[i++] = new Map("camocow","Camo Cow Skin",534,"-1",-1);
| >
| >
| >I want to open each file
|
|
| perldoc -f open
also had to do some learning with File::Spec, and with the builtins
readdir and opendir, but I think I've nailed down the basics. It isn't
as complex as I'd originally imagined it to be.
(yeah yeah newbie this :D )
| >in succession,
|
| >extract ONLY the information
| >between the () 's
| >on any line starting with 'maps[i++]'
|
|
| next unless /^\Qmaps[i++] = new Map(\E([^)]+)/;
| my $args = $1;
thanks, this helped a lot, since I'm really unfamiliar with regexps..
the test "print" produced the correct output, so you have my thanks for
producing a snippet of usefulness :)
I'm stuck with appending the input to an array though... (see previous
post on this subject)
| >and append it to
| >an output file
|
|
| perldoc -f open
got it
| >created with today's date and time as the filename, of
| >the form YYYY.MM.DD.HH.mm.txt (HH.mm being 24-hour time)
|
| perldoc -f localtime
ok that helps
| >each line will be it's own 'record', comma delimited, terminated by \n
| >
| >the output file will be called maps_database.txt
|
| So which is it?
|
| "maps_database.txt" or "YYYY.MM.DD.HH.mm.txt"?
duh :) uhm, both? :) *shaking my head*
| >what would be the most elegant and efficient means to accomplish this
| >in perl?
|
| It sounds rather straightforward.
|
| Where's the code you have written so far?
|
| Post it (if it's not too long), and we will help you fix it.
see previous post for my test-in-progress.
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
Date: Mon, 08 May 2000 18:13:17 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Need LWP module, but it's not installed on my server
Message-Id: <7au2g89ah1.fsf@Merlin.i-did-not-set--mail-host-address--so-shoot-me>
Hardy Merrill <hmerrill@my-deja.com> writes:
> Guru's please correct me if I'm wrong - I'm not sure what your setup is,
> but you will need to have LWP *installed*(not just drop certain files
> into certain directories) on the web server machine. I'm not sure if
> you have to be "root" in order to do the installation(of LWP), but you
> probably do. The installation will place LWP under the "site_perl"
> directory on that(web server) machine, which ensures that it will be
> found on the @INC perl path.
This is not completely correct. You can install modules anywhere you
like provided you have the proper permissions. So, even if you are not
root, you can still install modules locally in your directory. But, if
you do that, then you should tell Perl where to find them. This is done
by modifying the @INC in your program.
All of this is of course very well explained in the FAQs:
Perlfaq8:
How do I keep my own module/library directory?
--Ala
------------------------------
Date: Mon, 8 May 2000 16:01:26 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Need LWP module, but it's not installed on my server
Message-Id: <slrn8he78m.ddt.tadmc@magna.metronet.com>
On Mon, 08 May 2000 17:00:39 GMT, Hardy Merrill <hmerrill@my-deja.com> wrote:
>In article <8f6qrk$gn0$1@nnrp1.deja.com>,
> Kerry Shetline <kerry@shetline.com> wrote:
>> I'm using a commercial web hosting service that runs my web site on an
>> Apache server (version 1.3.9) which supports Perl CGIs, but the LWP
>> module doesn't seem to be installed. I don't exactly have sysadmin
>> privileges here -- I can't even telnet to the server to see what is
>and
>> isn't installed.
>>
>> Can I install the Perl modules I need into my own cgi-bin directory?
Yes.
But you said you don't even have telnet access, so how can
you get a command line to install from?
Perl FAQ, part 8:
"How do I keep my own module/library directory?"
>>I
>> tried the simple-minded approach of just dropping the LWP.pm file and
>> LWP folder from a set of Perl libraries I have into my cgi-bin
>> directory,
How did you do that without telnet (or similar) ?
>> with the not-too-surprising result of getting nothing but
>the
I expect you left out this step:
Perl FAQ, part 8:
"How do I add a directory to my include path at runtime?"
>> standard, less-than-useful "Internal Server Error" message back.
That is your _web server_ being unhelpful.
perl _is_ being helpful by printing diagnostics on STDERR, but
your web server is likely squirreling them away someplace where
you cannot see them.
Find out (from your provider's sysadmin) how to access the
server logs, or use CGI::Carp to have STDERR output show
up in the web page itself.
>> All the documentation I've seen on installing Perl modules assumes
>that
>> you have the run of the system, not that you're stuck with limited
>> access privileges.
I guess you have not seen Perl FAQ part 8 then.
>>Is there anything I can do other than plead with
>>the
>> sysadmin?
Try what is says in the FAQs.
>Guru's please correct me if I'm wrong -
Please don't guess.
It is Very Good of you to try and help out here, but if you
find yourself needing to make a disclaimer like the above,
that should be a sign to not post your guess.
Please continue to address questions that you _know_
the answer too. We need all the answerers we can get.
I am nowhere near a guru, but I still feel compelled to
correct what you have said.
Now I won't have time to answer someone else's question.
Someone else would have gotten their question answered if
you had not posted your followup...
>I'm not sure what your setup is,
>but you will need to have LWP *installed*(not just drop certain files
>into certain directories) on the web server machine.
The "installation" for many (most?) Perl modules *is* just
copying files around.
If you do it exactly right, you can "install" it manually.
But that is error prone, and you don't _need to_ install
it manually, you can still let the machine do all of
the installation steps for you, as described in the
above mentioned FAQ answer.
>I'm not sure if
>you have to be "root" in order to do the installation(of LWP), but you
>probably do.
You don't.
>The installation will place LWP under the "site_perl"
>directory on that(web server) machine, which ensures that it will be
>found on the @INC perl path.
The combination of the above 2 FAQ answers can make LWP visible
in *any* directory. You are not required to put them in site_perl/
>Hope this helps.
I don't think it did.
You basically said "get the sysadmin to do it", which had already
occurred to the OP, and he _shouldn't_ have to rely on the
sysadmin anyway (if he can get shell access somehow).
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 08 May 2000 21:12:06 GMT
From: Kerry Shetline <kerry@shetline.com>
Subject: Re: Need LWP module, but it's not installed on my server
Message-Id: <8f7ain$3r1$1@nnrp1.deja.com>
In article <u966spgebj.fsf@wcl-l.bham.ac.uk>,
nobull@mail.com wrote:
> Did you perhaps forget to do "use lib" too to tell Perl to look for
> files in the place you put them?
Nope, didn't miss that :) In fact, I tried putting a "use LWP::Simple" line
in before I actually accessed any part of the library, and that was enough to
invoke the dread "Internal Server Error".
At least "use Socket" works, so I'm able to talk directly to a socket to do
some simple HTTP in the meantime.
-Kerry
-----------------------------------------------------------------------
See the stars (and Sun, and Moon, and planets) at the Sky View Cafe...
http://www.shetline.com/skyview.html
-----------------------------------------------------------------------
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 8 May 2000 21:39:08 GMT
From: The WebDragon <nospam@devnull.com>
Subject: Re: Need LWP module, but it's not installed on my server
Message-Id: <8f7c5s$1a9$2@216.155.32.56>
In article <3915858E.B60AD731@shetline.com>, Kerry Shetline
<kerry@shetline.com> wrote:
| All the documentation I've seen on installing Perl modules assumes that
| you have the run of the system, not that you're stuck with limited
| access privileges. Is there anything I can do other than plead with the
| sysadmin?
plead to the sysadmin;
o indicate the correct url to the documentation and gzipped tarball
of the module you need on the CPAN,
o tell them WHY you need it,
o include a snippet of code using it,
o offer to show them the entire script if they should request so,
(to facilitate YOUR request).
I've found that by and large, this approach works well, as the sysadmin
doesn't have to do all the work to find the module that way, plus you're
being specific as to your needs, and generally being helpful rather than
a hindrance or annoyance. (:
usually you'll either get an denial with reasons or a terse "installed"
reply from the admin. :)
doing a little research beforehand to make sure of compatibility
http://testers.cpan.org/ with the module you need, and the version of
the OS they run, goes a LONG way towards getting what you need.
if the module version you are using is not compatible with their system
either try and use the previous release, or request that they test it,
(after previewing the release notes and determining what changed)
Sysadmins are generally reluctant to break pre-existing scripts, so
updating something like CGI.pm requires a little foresight on your part
in assuring them that compatiblity between their version and the one you
need is retained. include a url for the change notes if possible so they
can preview it without having to search.
any time you can save them is points in your favor, and shows you are
interested in HELPING THEM as well as helping yourself. :)
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
Date: Mon, 08 May 2000 18:19:52 GMT
From: john@thinman.com
Subject: Newbie Relief!! perl_primer rel 0.99 (pUrl was taken :)
Message-Id: <8f70fk$nhc$1@nnrp1.deja.com>
Ok folks, this is your big chance. Flame _ME_, not the primer :)
Take this how its meant, baby steps. And just like kids, newbies have a
short attention span, need instant gratification and whine like nobody's
business when the the speaker gets technical.
Hence the perl primer.
Please check the procedural server script. I know, I know... it used to
fork thanks to Tom C but NT doesn't and I haven't a clue about
multithreading.
I am also lost in the OO / file descriptor area, I really tried to make
a module out of the server. I also tried to understand the IO::Socket
section on that and noticed the solution but...
Next I am going to put a simple script behind tcpserver, maybe the slurp
module.
If you dont know this is a really cool replacement for inetd. After an
hour or so of frustration I suddenly remembered why the default has
always been to roll yer own from a tgz.
TIA,
thinman@puny.vm.com
oh, yeah, I got the ezmlm going and I need some cgi forms for sign-ins
and cookies and the like - now dont make me go to matt :)
##############################################
# CXN, Inc. Contact: john@thinman.com #
# Proud Sponsor of Perl/Unix of NY #
# http://puny.vm.com/puny #
##############################################
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 08 May 2000 16:51:54 -0500
From: "Andrew N. McGuire" <andrew.mcguire@walgreens.com>
Subject: Re: Newbie Relief!! perl_primer rel 0.99 (pUrl was taken :)
Message-Id: <391736FA.A0C178DA@walgreens.com>
john@thinman.com wrote:
>
> Ok folks, this is your big chance. Flame _ME_, not the primer :)
>
> Take this how its meant, baby steps. And just like kids, newbies have a
> short attention span, need instant gratification and whine like nobody's
> business when the the speaker gets technical.
>
> Hence the perl primer.
>
> Please check the procedural server script. I know, I know... it used to
> fork thanks to Tom C but NT doesn't and I haven't a clue about
> multithreading.
>
> I am also lost in the OO / file descriptor area, I really tried to make
> a module out of the server. I also tried to understand the IO::Socket
> section on that and noticed the solution but...
>
> Next I am going to put a simple script behind tcpserver, maybe the slurp
> module.
>
> If you dont know this is a really cool replacement for inetd. After an
> hour or so of frustration I suddenly remembered why the default has
> always been to roll yer own from a tgz.
[ snip ]
huh? I think your wording is somewhat unclear.
[ aside: http://puny.vm.com/perl_primer ]
Are you asking the NG to evaluate your Perl primer? At the very least,
in the 'Procedural Server' script I would run with warnings enabled,
via '-w'. Also in your 'one-liners' doc you say:
"An array is a list of scalars and is 0 by the @ sign."
I really think this can be worded better, perhaps:
"An array is a container for a list of scalars, in which each
element has a unique index. The index starts at 0 and
is incremented by one for each element in the array. For example:
The first element in @array is reffered to as $array[0],
the second as $array[1], etc..."
Of course you could and probably should refer to the Perl
documentation in your Primer, as the definitive answer on these
matters. While I understand that you want to simplify things, I
would not assume everyone to be a dolt. Do not oversimplify, or
at list 'KISS', but make reference to the appropriate docs.
That's my 2 cents. [ after only a quick glance ]
anm
--
Andrew N. McGuire
andrew.mcguire@walgreens.com
------------------------------
Date: Mon, 08 May 2000 19:15:41 GMT
From: John from PUNY <john@thinman.com>
Subject: Re: Newbie Relief!! URL is http://puny.vm.com/perl_primer
Message-Id: <8f73oc$rgl$1@nnrp1.deja.com>
Sorry:
Thats http://puny.vm.com/perl_primer
##############################################
# CXN, Inc. Contact: john@thinman.com #
# Proud Sponsor of Perl/Unix of NY #
# http://puny.vm.com #
##############################################
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 08 May 2000 18:48:01 GMT
From: john@thinman.com
Subject: Re: Newbie Relief: http://puny.vm.com/perl_primer
Message-Id: <8f724q$peo$1@nnrp1.deja.com>
Sorry, thats
http://puny.vm.com/perl_primer
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 8 May 2000 16:21:34 -0400
From: "Erick Jensen" <erick.jensen@unisys.com>
Subject: Perl code to check for broken links
Message-Id: <8f77kh$aul$1@mail.pl.unisys.com>
I am looking for some simple code to check whether a link is broken or not
(i.e., a subroutine with a URL parameter that returns whether that link is
broken or not). I want to incorporate this into a script I am writing. How
would I go about doing this? I looked on cgi-resources.com and found a
script that does this and a lot more, but it was too long and confusing (no
comments) to make sense of it. Thanks in advance.
-Erick Jensen
------------------------------
Date: 08 May 2000 21:04:07 GMT
From: bob4dummys@aol.com (Bob4dummys)
Subject: Perl with VRML
Message-Id: <20000508170407.07409.00001876@ng-cl1.aol.com>
I recently go a book on VRML, and in it is a PERL script to make a VRML file.
When opened the file should produce a VRML file (world).
This is the code, please tell me how I can make it open as a VRML file, not
just as a bunch of text. (Please reply via email)
#!/usr/bin/perl
#
# Sample Orrey VRML server-side script written in PERL
# Written by Mark Pesce, June 1995
# No rights reserved.
#
# Let's do some time math.
#
# Get seconds since start of 1995.
# First get seconds as of 1 Jan 1995.
# We cheated and precalculated this number.
# We cheated and got the number of seconds in a year, as well.
# Oh, alright, we did it for the seconds in a lunar month, too!
#
$yearZero = 788918400;
$secInYear = 31557600;
$secInLuMonth = 2514360;
$rightNow = time ();
$sinceZero = $rightNow - $yearZero;
#
# Calculate how far along we are in Earth's orbit around the sun.
#
$theSpin = ($sinceZero / $secInYear) * (3.1416 * 2);
#
# So now calculated x SIN and y COS values for Earth's position around the Sun
# The value of 20 is preserved from the original Translation node
#
$xVal = 20 * sin($theSpin);
$zVal = 20 * cos($theSpin);
#
# Do precisely the same thing for the Moon's orbit around the Earth
#
$laLune = ($sinceZero / $secInLuMonth) * (3.1416 * 2);
$xMoon = 4 * sin($laLune);
$yMoon = 4 * cos($laLune);
#
# Begin the script's output.
# Always send the content type before everything else
#
print "Content-type: x-world/x-vrml\n\n";
#
# Then send the file header
#
print "#VRML V1.0 ascii\n";
#
# First, define the Sun.
#
print "Separator { Material { emissiveColor 1 1 0 } Pointlight { intensity 1
color 1 1 0.9 } \n";
print "Sphere { radius 10 }\n";
#
# Next, the Earth.
#
print "Separator {\n";
print "Transform { translation ";
printf "%g %g 0 }\n", $xVal, $zVal;
print "Material { diffuseColor 0 0 1 specularColor 0.9 0.9 0.9 shininess 0.9
}\n";
print "Texture2 { filename \"http://rs560.cl.msu.edu/weather/worldir.gif\" }
Sphere { radius 2 }\n";
#
# Finally, the Moon.
#
print "Separator {\n";
print "Transform { translation ";
printf "%g %g 0 }\n", $xMoon, $yMoon;
print "Material { diffuseColor 0.7 0.7 0.7 shininess 0.3 } Texture2 { image 4 4
3\n";
print "0xC0C0C0 0x808080 0xFFFFFF 0x404040 0x808080 0x202020 0x808080
0xC0C0C0\n";
print "0x202020 0x808080 0xFFFFFF 0x808080 0x808080 0xC0C0C0 0x808080 0x202020
}\n";
print "Sphere { radius 1 } } } }\n";
#
# All done.
#
This was copied directly out of the book, so there should be no errors.
Thanks.
------------------------------
Date: Mon, 08 May 2000 21:37:35 GMT
From: ra jones <ra_jones@my-deja.com>
Subject: Please check my 'random' code
Message-Id: <8f7c2t$5at$1@nnrp1.deja.com>
I'm fairly new to Perl, but learning fast (I hope). Could some-one check
my code please. I need to generate a random return from two choices for
a medical experiment where one of two treatments are given, allocated at
random. The code I have used is as below:
@treat = ('Test','Control');
srand(time ^ $$);
$N = @treat;
$N = int(rand($N));
open(FILE,">>$log"); # path to $log specified elsewhere
print FILE "$treat[$N]\n";
close(FILE);
perl -v at command line says: Perl 5.005_03 built for i686-linux.
The question is, are there any theoretical (or practical) objections to
this. I have read somewhere that Perl may not in fact generate genuinely
random numbers (probably referred mainly to cryptography). I just need
the snippet to simulate the toss of a coin. Also, I have read the thread
on 'Random number' elsewhere on this forum, but must admit I can't
follow it all. Any help much appreciated.
--
ra jones (posted via deja.com)
address for e-mail reply:
rajones(at)mail.com
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 08 May 2000 20:32:44 GMT
From: "Jason Malone" <jamalone@earthlink.net>
Subject: Re: Printing Arrays
Message-Id: <MvFR4.38976$x4.1281496@newsread1.prod.itd.earthlink.net>
"Eric Hueckel" <eric.hueckel@vitesse.com> wrote in message
news:3916DA0B.547CBF4F@vitesse.com...
> To All,
>
> I am trying to print individual elements of
> an array using a loop structure as follows:
>
> for ($i = $num_modules; $i >= 1; $i--) {
>
> print $block[$i],"\n";
>
> }
>
You could also try
foreach (@block) {
print $_;
}
hth
Jason Malone
------------------------------
Date: 08 May 2000 15:37:04 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Printing Arrays
Message-Id: <87k8h4pymn.fsf@shleppie.uh.edu>
>> On Mon, 08 May 2000 20:32:44 GMT,
>> "Jason Malone" <jamalone@earthlink.net> said:
> "Eric Hueckel" <eric.hueckel@vitesse.com> wrote in
> message news:3916DA0B.547CBF4F@vitesse.com...
>> To All,
>>
>> I am trying to print individual elements of an array
>> using a loop structure as follows:
>>
>> for ($i = $num_modules; $i >= 1; $i--) {
>>
>> print $block[$i],"\n";
>>
>> }
>>
> You could also try
> foreach (@block) { print $_; }
Now, why over-elaborate things? :-)
print "$_\n" for @block;
hth
t
------------------------------
Date: Mon, 08 May 2000 20:40:43 GMT
From: "Jason Malone" <jamalone@earthlink.net>
Subject: Re: Printing Arrays
Message-Id: <fDFR4.38997$x4.1283757@newsread1.prod.itd.earthlink.net>
"Tony Curtis" <tony_curtis32@yahoo.com> wrote in message
news:87k8h4pymn.fsf@shleppie.uh.edu...
> >> On Mon, 08 May 2000 20:32:44 GMT,
> >> "Jason Malone" <jamalone@earthlink.net> said:
>
> > "Eric Hueckel" <eric.hueckel@vitesse.com> wrote in
> > message news:3916DA0B.547CBF4F@vitesse.com...
> >> To All,
> >>
> >> I am trying to print individual elements of an array
> >> using a loop structure as follows:
> >>
> >> for ($i = $num_modules; $i >= 1; $i--) {
> >>
> >> print $block[$i],"\n";
> >>
> >> }
> >>
> > You could also try
>
> > foreach (@block) { print $_; }
>
> Now, why over-elaborate things? :-)
>
> print "$_\n" for @block;
>
> hth
> t
>
Just a style issue :)
Jason
------------------------------
Date: Mon, 08 May 2000 18:43:23 GMT
From: Paul S R Chisholm <psrchisholm@my-deja.com>
To: Larry Rosler <lr@hpl.hp.com>, bart.lateur@skynet.be (Bart Lateur)
Subject: Re: problems with $/ = "\r\n" (Windows text files and $INPUT_RECORD_SEPARATOR)
Message-Id: <8f71s7$pac$1@nnrp1.deja.com>
In article <3917a5ad.14160818@news.skynet.be>, bart.lateur@skynet.be
(Bart Lateur) wrote:
> Don't do it. Unless you do binmode() on the input file handle, Perl
will convert CR+LF into "\n" (=LF) for you, and convert it back on
output (unless, again, you used binmode() on the output handle).
Right.
PSRC:
> > ... If I comment out the line that sets $/ I don't see any
problems (but I can't call chomp() to get rid of the logical end-of-
line).
In article <MPG.137cd6c98e3fc35898aa0c@nntp.hpl.hp.com>, Larry Rosler
<lr@hpl.hp.com> wrote:
> Of course you can. The 'logical end-of-line is "\n", which is the
default value for $/, which chomp() chomps.
> I suggest you read the first section in perlport, headed 'Newlines'.
Excellent reference; thanks!
I got distracted by two things.
First, perlvar says $/ is "\n" (on all platforms); I hadn't realized
what "\n" means (i.e., \015\012 for MS-DOS text files), but I do now
that I've read perlport.
Second, my first file, instead of having lines that were \015\012
terminated, had lines that were \015\015\012 terminated. (I guess it
was FTP'ed, translating \012 to \015\012, one too many times.) After <>
and chomp(), the lines still had trailing \015 characters. Munging $/
worked for this file. My second file was \015\012 terminated; setting
$/ meant that <> was looking for \015\012 *after* the \015 had already
been stripped off. Result: reading the second file led to an attempt to
read a very long (43 megabytes) line into $_ (oops).
Better answer: fix the wacky file, not the Perl. --PSRC
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 08 May 2000 20:20:37 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: program that prints itself
Message-Id: <39172194.6647$16c@news.op.net>
In article <slrn8h0pq8.81q.tadmc@magna.metronet.com>,
Tad McClellan <tadmc@metronet.com> wrote:
>>When run, it will produce itself as output. (This even works under
> ^^^^^^^^^^^^^^
>
>But it does not do that.
>
>It produces the _same output_ as the source, but it is not
>the _source itself_.
Well, that's what quine programs are supposed to do. Pseudo-quine
programs that open the source code file and print out the source are
usually considered to be cheating.
The idea is to write a program that *generates* its own source code.
Copying it from elsewhere is cute, but misses the point.
A more legitimate criticism of my program might be that it doesn't
produce its entire source code, because it depends on data that is
embedded in Perl, and it doesn't emit Perl itself as part of its
output.
>Easily seen by doing s/quine\.pl/FOO/ in the program,
>and running it as before.
``This isn't a payroll reporting program!''
``Why not?''
``Because it produces incorrect output if you do s/p/!/g on
the source code.''
Well, no duh. Of course it won't do what it is supposed to do, if you
alter the source code first. No programs will. This complaint
reminds me a little of the person who said that vi is bad becuse it
doesn't work if you put jelly in your keyboard.
------------------------------
Date: Mon, 08 May 2000 20:34:23 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: program that prints itself
Message-Id: <391724cf.677e$5e@news.op.net>
In article <8epj84$19m$1@pegasus.csx.cam.ac.uk>,
M.J.T. Guy <mjtg@cus.cam.ac.uk> wrote:
>[ Drifting off-topic, but what the hell ... ]
> Produce the shortest piece of paper tape, which when fed into
> the EDSAC II will punch out a copy of itself *reversed*.
>
>This was won by Peter Swinnerton-Dyer with an iterative solution:
>
> Take a random piece of paper tape from a rubbish bin.
> Feed it into the computer.
> Take the output, reverse it and feed it into the computer.
> Take the output, reverse it and feed it into the computer.
> ...
>
>In practice this converged after about two iterations.
Sometimes you get lucky, sometimes not.
On the #perl channel on IRC, there is a `nickometer' feature that
tells you how lame someone's nickname is. For example:
-> *purl* nickometer tchrist
*purl* the 'lame nick-o-meter' reading for tchrist is 0%
-> *purl* nickometer MyT-HaX0R
*purl* the 'lame nick-o-meter' reading for MyT-HaX0R is 99.87%, yrlnry
Now let's suppose we want to find a fixed point for this function.
-> *purl* nickometer 99.78%
*purl* the 'lame nick-o-meter' reading for 99.78% is 54%, yrlnry
-> *purl* nickometer 54%
*purl* the 'lame nick-o-meter' reading for 54% is 28%, yrlnry
-> *purl* nickometer 28%
*purl* the 'lame nick-o-meter' reading for 28% is 25%, yrlnry
-> *purl* nickometer 25%
*purl* the 'lame nick-o-meter' reading for 25% is 28%, yrlnry
Oh well; so much for that.
It turns out that the string '34%' yields a reading of 34%, and
similarly the string '%43' also yields a reading of 34%, so as I said,
you have to get lucky, because often these things don't converge at
all. I'd be a little surprised if Swinnerton-Dyer's solution produced
the *shortest* possible tape, which was what you said was asked for.
But since it seems to me that the shortest possible tape is the empty
tape, which produces an empty output, I can imagine that maybe
Swinnerton-Dyer's procedure did indeed yield the empty tape; at some
point you happen to enter a tape that produces an empty output, and
there's your fixed point.
A related puzzle is to find an 11-character string which is a fixed
point of the function
crypt('XX' . $string, "XX");
If the crypt() function is well-designed, an iterative method will not
work. About fifteen yers ago I iterated crypt() ten thousand times
just to make sure. (This took a lot longer then than it would today.)
The results were reassuringly random.
------------------------------
Date: Mon, 08 May 2000 18:06:52 GMT
From: Rob <Rob@barbados.cc>
Subject: Programmer Required
Message-Id: <39170237.12385480@barbados.cc>
Hi,
I am in need of a programmer to create and refine a cgi script for a new
site project. This project has very good potential with larger
corporations as its target. I have a base demo almost working (hacking
on my own)to give you a good idea of what is required before you start.
There is a lot of work in this but there is nothing required here that
cannot and has not already been done with a Perl CGI script. To give you
and Idea of the work load I have been quoted $3000.00 to $6000.00 to
write and customize it, and actually if I just wanted to buy a service I
had budgeted over $10,000.00 to get it done fully and right.
The fact is for this project to do as well as it should or could, it
requries a programmer as part of the business with a Full Interest it
having it succeed. This would be so that the program would always be on
the go being fine tuned and perfected to keep the site as the ONLY and
best service of its kind on the internet.
yada yada yada...this crux here is I need more of a partner in this than
a hired gun. Anybody willing to take a risk with their time as their
part of the investment. Contact me ASAP.
The Project requires a good knowledge of DBs and their manipulation and
it would help if you have an easy going look on life (for working
together).
Rob Gouriluk
Rob@Barbados.cc
P.S. If I do fail to find someone to work with here I will be needing a
GOOD hired gun. So if small to mid size Web DB's are your game please
reply with some sort of E busines card ...as I might be in need of your
Services.
------------------------------
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 2981
**************************************