[19223] in Perl-Users-Digest
Perl-Users Digest, Issue: 1418 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 31 18:05:45 2001
Date: Tue, 31 Jul 2001 15:05:11 -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: <996617111-v10-i1418@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 31 Jul 2001 Volume: 10 Number: 1418
Today's topics:
$ENV{'HTTP_REFERER'} (Tell)
Re: $ENV{'HTTP_REFERER'} <yanoff@yahoo.com>
Re: Cleaning replacing the value of a constant <godzilla@stomp.stomp.tokyo>
FAQ: What is the difference between a list and an array <faq@denver.pm.org>
Re: Finding "this" but not "this and that" with a regex <ren@tivoli.com>
Re: Finding "this" but not "this and that" with a regex (Jay McGavren)
Re: Finding a word in a sorted list. (Mario Rizzuti)
Having some trouble with map (John Kramer)
Re: Having some trouble with map (John Joseph Trammell)
Re: Having some trouble with map <andras@mortgagestats.com>
Re: Having some trouble with map <uri@sysarch.com>
Re: Having some trouble with map ctcgag@hotmail.com
Re: Having some trouble with map <carlos@plant.student.utwente.nl>
Re: Help on Array ? <krahnj@acm.org>
Re: Help Please <krahnj@acm.org>
Re: Help with an array and foreach <scott@nospamthankx.here.there.org.co.uuk>
Re: negative lookahead <if.xoboi@jks.invalid>
Re: negative lookahead (Abigail)
newnews using Net::NNTP <kencox@us.ibm.com>
OT: spelling (was Re: chess in perl) <if.xoboi@jks.invalid>
Re: OT: spelling (was Re: chess in perl) <flavell@mail.cern.ch>
Re: OT: spelling (was Re: chess in perl) <lmoran@wtsg.com>
OT: Writting Perl code that doesn't suck (Was: Strange <ilya@martynov.org>
Re: perl and Informix (Abigail)
pod question (Doug McGrath)
Re: RegExp <weiss@kung.foo.at>
Reporting Questionable Programming Activity (Smiley)
Re: simple IO::Select problem on Win32 <dbe@wgn.net>
Re: sorting by a hash of arrays - how to elegantly exte <mjcarman@home.com>
Re: Strange problem... <godzilla@stomp.stomp.tokyo>
Re: Strange problem... <slash@dot.n.e.tuk>
Re: Telnet/MUD server <philip@zaynar.demon.co.uk>
Toke::Parser woes... (Salvador)
use Cwd <ericd_@hotmail.com>
Re: use Cwd <ilya@martynov.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 31 Jul 2001 20:27:48 GMT
From: tezslater@aol.com.remove (Tell)
Subject: $ENV{'HTTP_REFERER'}
Message-Id: <20010731162748.06436.00002313@ng-fy1.aol.com>
I am using a perl cgi script that uses the $ENV{'HTTP_REFERER'} variable to
make sure that it is being run from only 1 web site as a security feature.
Someone has told me that these variables can be easily faked.
I do not want to know how to fake them :-) but would like to know if this is
actually possible because if it is I am not as secure as I thought I was.
Thanks Tell.
------------------------------
Date: Tue, 31 Jul 2001 16:06:19 -0500
From: Scott Yanoff <yanoff@yahoo.com>
To: Tell <tezslater@aol.com>
Subject: Re: $ENV{'HTTP_REFERER'}
Message-Id: <3B671DCB.559F358C@yahoo.com>
Tell wrote:
>
> I am using a perl cgi script that uses the $ENV{'HTTP_REFERER'} variable to
> make sure that it is being run from only 1 web site as a security feature.
> Someone has told me that these variables can be easily faked.
>
> I do not want to know how to fake them :-) but would like to know if this is
> actually possible because if it is I am not as secure as I thought I was.
Yes, then can be faked. The browser chooses to send the HTTP_REFERER.
If someone were to write their own browser, they could therefore choose
whatever they wanted it to send for HTTP_REFERER.
Hope that helps,
--
-Scott
yanoff@yahoo.com | http://www.yanoff.org | AOL IM: SAY KJY
------------------------------
Date: Tue, 31 Jul 2001 12:11:37 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Cleaning replacing the value of a constant
Message-Id: <3B6702E9.60FEE050@stomp.stomp.tokyo>
Godzilla! wrote:
> Bernie Cosell wrote:
> > Godzilla! wrote:
> > } Bernie Cosell wrote:
(snipped)
> > } use Fcntl ":Fcompat";
> > } use constant F_SETLKW;
> > doesn't work....
> use Fcntl ":Fcompat";
> use constant F_SETLKW => 2;
> use constant F_WRLCK => 4;
> use constant F_RDLCK => 6;
* smugly satiated with her multi-layered con *
As I have said to you many times and do say now
with a rather delightful demure smile,
"Never try to con, a con."
Godzilla! Queen Of Con.
------------------------------
Date: Tue, 31 Jul 2001 18:19:38 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: What is the difference between a list and an array?
Message-Id: <_EC97.10$l_m.191598080@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
What is the difference between a list and an array?
An array has a changeable length. A list does not. An array is something
you can push or pop, while a list is a set of values. Some people make
the distinction that a list is a value while an array is a variable.
Subroutines are passed and return lists, you put things into list
context, you initialize arrays with lists, and you foreach() across a
list. "@" variables are arrays, anonymous arrays are arrays, arrays in
scalar context behave like the number of elements in them, subroutines
access their arguments through the array "@_", and push/pop/shift only
work on arrays.
As a side note, there's no such thing as a list in scalar context. When
you say
$scalar = (2, 5, 7, 9);
you're using the comma operator in scalar context, so it uses the scalar
comma operator. There never was a list there at all! This causes the
last value to be returned: 9.
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
04.37
--
This space intentionally left blank
------------------------------
Date: 31 Jul 2001 14:34:40 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Finding "this" but not "this and that" with a regex?
Message-Id: <m3itg8evu7.fsf@dhcp9-161.support.tivoli.com>
On Tue, 31 Jul 2001, tsee@gmx.net wrote:
> "Jay McGavren" <sgarfunkle@hotmail.com> schrieb im Newsbeitrag
> news:6bb557e1.0107302114.696bc739@posting.google.com...
>
> #untested, sorry. Should work though.
>
>> sub CanYouIgnore {
>> $Record = shift;
> my @notIgnorePhrases = ('and that');
>> @IgnorePhrases = ("other thing", "this");
>>
>> $Ignore = 0;
> my $ignorePhrase;
> foreach $ignorePhrase (@IgnorePhrases) {
> my $notIgnorePhrase;
> foreach $notIgnorePhrase (@notIgnorePhrases) {
> $Ignore = 1 if ( $Record =~ /$ignorePhrase/m && !($Record =~
> /$notIgnorePhrase/m) );
> }
> }
>> print "$Record\n" unless $Ignore;
>> }
Better to simply check the @notIgnorePhrases first and don't bother to
check for @IgnorePhrases if a notIgnore matches. Also, if all of the
phrases are just that, then there is no need for pattern matching --
just use index().
sub CanYouIgnore {
my $record = shift;
my @notIgnorePhrases = ('and that');
my @IgnorePhrases = ('other thing', 'this');
print "$record\n" if grep { index($record, $_) > -1 } @notIgnorePhrases
or ! grep { index($record, $_) > -1 } @IgnorePhrases;
}
If regexen are needed, the index() calls can easily be change to
matches.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 31 Jul 2001 14:20:44 -0700
From: sgarfunkle@hotmail.com (Jay McGavren)
Subject: Re: Finding "this" but not "this and that" with a regex?
Message-Id: <6bb557e1.0107311320.579caa2d@posting.google.com>
> anywhere in the Record. This would do it:
> if ($Record =~ /this/ && $Record !~ /that/)
Oops; I'm getting this backwards and possibly confusing the hell out
of everyone. What I'm really looking for:
if ($Record =~ /this/ && $Record =~ /that/)
...and I guess the subject line is a little inaccurate, too. :/
------------------------------
Date: 31 Jul 2001 12:54:18 -0700
From: mariorizzuti@yahoo.com (Mario Rizzuti)
Subject: Re: Finding a word in a sorted list.
Message-Id: <42f3ee2.0107311154.291404d3@posting.google.com>
Bart Lateur <bart.lateur@skynet.be> wrote in message news:<3ffbmtses8pi3o53mka221svn1djc4do0r@4ax.com>...
> M.J.T. Guy wrote:
>
> >Bart Lateur <bart.lateur@skynet.be> wrote:
> >>Mario Rizzuti wrote:
> >>>
> >>>I am wondering what is the fastest possible way to find the associated
> >>>numbers of a given list of usernames?
> >>
> >>Theoretically: binary search. I would think.
> >
> >Nope. Hash lookup will always beat it ( O(1) rather than O(log n), with
> >good constants ).
> >
> >Provided you can afford the memory, of course.
> I was talking about searching it on disk. Your approach requires first
> loading the hash.
In fact I have found that whatever solution one approaches, almost all
of the time is spent in accessing the disk. The goal should be how to
use the disk as few as possible (eg. searching in a way that the disk
head moves as few as possible as someone suggested).
Also, strange enough to me, it seems (benchmarked only on win32) that
reading a record (one) in a DB_File is slower (about the double of the
time) than performing a binary search on a sorted Fixed-Length-Records
file.
Where the flat file is really faster than the DBM file is in opening
it (also because the DBM file is much larger).In the actual reading of
the key, the DBM was a little faster.
I have tested it with various file sizes from 500 to 250,000 records
with similar results.
Mario Rizzuti
------------------------------
Date: 31 Jul 2001 12:45:11 -0700
From: kramer@email.arizona.edu (John Kramer)
Subject: Having some trouble with map
Message-Id: <96db72f6.0107311145.2c2dceec@posting.google.com>
Hello,
I have a bit of code that seems to me should work but it is generating
an error. The code follows and the error is :
Modification of a read-only value attempted
In this snippet of code the @port array is an array with each element
of the array being a reference to an anonymous hash with the keys
(port_mac,port,index)
$port = shift @walk;
map {if ($_->{port_mac} eq $mac) {$port = ($_->{port})}} @port;
From everything I have read this should work. Am I missing something?
John Kramer
Senior Systems Programmer
University of Arizona
------------------------------
Date: 31 Jul 2001 20:06:19 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: Having some trouble with map
Message-Id: <slrn9me1l1.51r.trammell@bayazid.hypersloth.net>
On 31 Jul 2001 12:45:11 -0700, John Kramer wrote:
> I have a bit of code that seems to me should work but it is generating
> an error. The code follows and the error is :
>
> Modification of a read-only value attempted
>
> In this snippet of code the @port array is an array with each element
> of the array being a reference to an anonymous hash with the keys
> (port_mac,port,index)
>
> $port = shift @walk;
> map {if ($_->{port_mac} eq $mac) {$port = ($_->{port})}} @port;
>
> From everything I have read this should work. Am I missing something?
1. are you sure the error message is caused by this code?
2. using map() in void context is frowned upon. What's wrong
with 'for'?
--
According to the Genesis account, the tower of Babel was man's second
major engineering undertaking, after Noah's ark. Babel was the first
engineering fiasco.
- F. Brooks, _The Mythical Man-Month_
------------------------------
Date: Tue, 31 Jul 2001 16:17:24 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: Having some trouble with map
Message-Id: <3B671254.79D335A6@mortgagestats.com>
John Joseph Trammell wrote:
> using map() in void context is frowned upon.
Why? What is wrong with using map() in void context?
------------------------------
Date: Tue, 31 Jul 2001 20:29:42 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Having some trouble with map
Message-Id: <x71ymw266i.fsf@home.sysarch.com>
>>>>> "AM" == Andras Malatinszky <andras@mortgagestats.com> writes:
AM> John Joseph Trammell wrote:
>> using map() in void context is frowned upon.
AM> Why? What is wrong with using map() in void context?
two issues. first it is inefficient as currently implemented (abigail, i
know your thoughts here). this may be corrected in 5.X or 6.
secondly, i (and many others) think it is semantically msidirecting the
reader of this code. map's (primary) purpose was to generate a new list
from the incoming list. the fact that it can also do side effects is
nice but not critical as you can do that with for loops or for
modifiers. in fact the for modifier was created to fill in that semantic
gap and not for any critical coding reasons. so map's well known
semantic purpose is being ignored when it is used in a void
context. yes, it works and it is not newbie level bad perl, but many
experienced dislike map in a void context.
and since your map block contained a full conditional block, it just
poor style regardless of the void context. the {} were hard to visually
parse and that is an important aspect to code style. that code would
be better written as a simple for loop with a block.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: 31 Jul 2001 20:52:38 GMT
From: ctcgag@hotmail.com
Subject: Re: Having some trouble with map
Message-Id: <20010731165238.943$Oh@newsreader.com>
kramer@email.arizona.edu (John Kramer) wrote:
> Hello,
>
> I have a bit of code that seems to me should work but it is generating
> an error. The code follows and the error is :
>
> Modification of a read-only value attempted
>
> In this snippet of code the @port array is an array with each element
> of the array being a reference to an anonymous hash with the keys
> (port_mac,port,index)
>
> $port = shift @walk;
> map {if ($_->{port_mac} eq $mac) {$port = ($_->{port})}} @port;
I get no error with this code. Perhaps you need to furnish examples of
@port, @walk, and $mac are that create the error.
> From everything I have read this should work. Am I missing something?
I don't know what you mean by "work". What is it supposed to do?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service
------------------------------
Date: Tue, 31 Jul 2001 22:43:30 +0200
From: "carlos" <carlos@plant.student.utwente.nl>
Subject: Re: Having some trouble with map
Message-Id: <9k77al$d4e$1@dinkel.civ.utwente.nl>
"Andras Malatinszky" <andras@mortgagestats.com> wrote in message
news:3B671254.79D335A6@mortgagestats.com...
>
>
> John Joseph Trammell wrote:
>
> > using map() in void context is frowned upon.
>
> Why? What is wrong with using map() in void context?
>
here we go again...
------------------------------
Date: Tue, 31 Jul 2001 19:33:52 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Help on Array ?
Message-Id: <3B67085B.A0BB1D41@acm.org>
Tim wrote:
>
> Could someone please help me on this ?
>
> Below is my script:
>
> @in1=(10); #Please DO NOT MODIFY the ARRAY
This is an array with _one_ element, perhaps you meant:
my @in1 = qw(1 0); # an array with _two_ elements
> @in2=(AB);
Same here.
my @in2 = qw(A B); # an array with _two_ elements
> $"="";
> for ($i=0;$i<=2;$i++){
^^^^^
Here you are iterating over _three_ numbers ( 0, 1, and 2 ), perhaps you
meant:
for ( $i = 0; $i < 2; $i++ ) {
> print "@in1[$i] @in2[$i]\n";
^ ^
Here you are using an array slice when you really want a scalar. If you
had warnings enabled then perl would have warned you about this.
print "$in1[$i] $in2[$i]\n";
> }
>
> THe ouput of the script above is:
>
> 10 AB
>
> However, I would like the output to be
>
> 1 A
> 0 B
>
> Any help would be greatly appriciate !!
So, to sum up:
#!/usr/bin/perl -w
use strict;
my @in1 = qw(1 0); # an array with _two_ elements
my @in2 = qw(A B); # an array with _two_ elements
for ( $i = 0; $i < 2; $i++ ) {
print "$in1[$i] $in2[$i]\n";
}
__END__
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 31 Jul 2001 19:37:35 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Help Please
Message-Id: <3B67093A.D4548B2A@acm.org>
Michael Carman wrote:
>
> News Only wrote:
> >
> > 4. Change the modify date back to the original one. ----- 07/28/2001
> > 12:53:42 AM
>
> Perl doesn't have a builtin to do this, which means you'll need to farm
> it out to you OS. You'll want to use either system() or backticks (``)
> to do this.
perldoc -f utime
utime LIST
Changes the access and modification times on each
file of a list of files. ...
> > 5. Must be able to read long file names like "urls_072840000.log"
>
> Also dependant on your OS. Perl doesn't care.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 31 Jul 2001 21:57:55 +0100
From: "Scott Porter" <scott@nospamthankx.here.there.org.co.uuk>
Subject: Re: Help with an array and foreach
Message-Id: <20010731.215755.1350573793.794@nospamthankx.here.there.org.co.uuk>
In article <3B66B038.5C0E8012@stomp.stomp.tokyo>, "Godzilla!"
<godzilla@stomp.stomp.tokyo> wrote:
> Helgi Briem wrote:
>
>> Godzilla! wrote:
>> >Ryan Gralinski wrote:
>
> (snipped)
>
>> >> What i need to know, is how can i start this loop at $start element
>> >> of the array
>> >> f.e instead of starting at $covers[0] start at $covers[1000]
[...cue dummy: Open mouth, expel garbage...]
>> >Due due to perl core automation, you cannot do this with a foreach
>> >loop; it starts at element zero. There is no trick I know of to do
>> >this. Perhaps others know.
>
>> Not so. For and foreach are exactly the same in function. Foreach is
>> just a more grammatical way of writing some things.
>
>
> I can easily surmise the end of your right index finger is heavily
> calloused from reading and, your brain is still infant soft and tender.
Translation: "Waaaaahhhh! No fair, no fair - you made me look
stooopid!!!! Waaaaahhhh!"
*giggle*
------------------------------
Date: Tue, 31 Jul 2001 21:35:46 +0300
From: Sami Jarvinen <if.xoboi@jks.invalid>
Subject: Re: negative lookahead
Message-Id: <MPG.15d10ff3bbaa9f93989691@news.yhteys.mtv3.fi>
Argh! My first post to clpm - riddled with bugs and other nonsense ;-)
Sami Jarvinen wrote:
> How about
>
> m/^aaa(.*)bbb$/is and $1 !~ /zzz/I;
Of course that should be
m/^aaa.*bbb$/is and !m/zzz/I;
Fixed typo (capital 'I'), removed redundant capturing (thanks to Philip
Newton who figured this out).
> > My attempt:
> > $mystring =~ m/aaa.*?(?!zzz)bbb/si;
> > Result:
> > Still matches even if the string contains zzz.
> > I'd expect the .*? to fail as soon as it hits the zzz?
>
> Try this:
>
> use re qw( debug );
> 'aaazzzbbb' =~ m/aaa.*?(?!zzz)bbb/;
I should've mentioned that the point of this exercise is to show the OP
what Perl's regex engine does with the pattern he came up with.
--
To demunge e-mail address, remove ".invalid" and reverse the rest.
See <URL:http://www.faqs.org/faqs/net-abuse-faq/munging-address/>
for details on "spam-blocking".
------------------------------
Date: 31 Jul 2001 20:28:40 GMT
From: abigail@foad.org (Abigail)
Subject: Re: negative lookahead
Message-Id: <slrn9me58t.d4m.abigail@alexandra.xs4all.nl>
Bart Lateur (bart.lateur@skynet.be) wrote on MMDCCCXCI September MCMXCIII
in <URL:news:8itbmt89u7daa13s6aur6m1smk8b3stqm5@4ax.com>:
:} Craig Berry wrote:
:}
:} >mike (rafalam@cadmus.com) wrote:
:} >: I want to match a string that starts with "aaa" and ends with "bbb" as
:} >: long as the is no "zzz" between aaa and bbb.
:} >
:} > /^aaa(?!.*zzz).*bbb$/
:}
:} Nope. That won't match anything in
:}
:} aaa====bbb==zzz
:}
:} either.
So? "aaa====bbb==zzz" doesn't end with "bbb", hence fails the requirements.
Not matching when it shouldn't match used to be good when I was a kid.
:} The problem is that the lookbehind should be restricted to inside the
:} candidate for the match.
But since the other requirements are for the beginning and the end of the
string, all other parts of the string are between the beginning and end.
Abigail
--
#!/opt/perl/bin/perl -w
$\ = $"; $SIG {TERM} = sub {print and exit};
kill 15 => fork for qw /Just another Perl Hacker/;
------------------------------
Date: Tue, 31 Jul 2001 16:26:08 -0500
From: "KEN" <kencox@us.ibm.com>
Subject: newnews using Net::NNTP
Message-Id: <9k77l9$lc0$1@ausnews.austin.ibm.com>
Hola,
I am trying to use the newnews method of Net::NNTP. I can get and read the
news from my news server, but I cannot understand the instructions for the
newnews method.
newnews ( SINCE [, GROUPS [, DISTRIBUTIONS ]])
SINCE is a time value. GROUPS is either a group pattern or a reference to a
list of group patterns. DISTRIBUTIONS is either a distribution pattern or a
reference to a list of distribution patterns.
Returns a reference to a list which contains the message-ids of all news
posted after SINCE, that are in a groups which matched GROUPS and a
distribution which matches DISTRIBUTIONS.
1. Specifically, what is a group pattern or a distribution in this case.
Also, what is the time value format?
could someone please give me an example of a line using this method?
Thanks,
Ken
------------------------------
Date: Tue, 31 Jul 2001 21:35:49 +0300
From: Sami Jarvinen <if.xoboi@jks.invalid>
Subject: OT: spelling (was Re: chess in perl)
Message-Id: <MPG.15d1113993180cb7989692@news.yhteys.mtv3.fi>
Anno Siegel wrote:
> According to Alan Barclay <gorilla@elaine.furryape.com>:
> > 1) Check the algorythmn. If you've got the wrong algorythmn, then you
> Apologies for the pedantry, but please: "algorithm".
Speaking of spelling, why do some people sometimes say 'optomize'
instead of 'optimize'?
--
To demunge e-mail address, remove ".invalid" and reverse the rest.
See <URL:http://www.faqs.org/faqs/net-abuse-faq/munging-address/>
for details on "spam-blocking".
------------------------------
Date: Tue, 31 Jul 2001 20:56:48 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: OT: spelling (was Re: chess in perl)
Message-Id: <Pine.LNX.4.30.0107312055200.19690-100000@lxplus023.cern.ch>
On Jul 31, Sami Jarvinen showed that inside every silver lining
there's a cloud:
> Speaking of spelling, why do some people sometimes say 'optomize'
> instead of 'optimize'?
Maybe they're thinking of optometrists, and trying to make a
spectacle?
------------------------------
Date: Tue, 31 Jul 2001 16:30:46 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: OT: spelling (was Re: chess in perl)
Message-Id: <t85emtgkkdiupt4ot383ovvch5d6utflbc@4ax.com>
On Tue, 31 Jul 2001 21:35:49 +0300, Sami Jarvinen
<if.xoboi@jks.invalid> wrote wonderful things about sparkplugs:
>Anno Siegel wrote:
>> According to Alan Barclay <gorilla@elaine.furryape.com>:
>> > 1) Check the algorythmn. If you've got the wrong algorythmn, then you
>> Apologies for the pedantry, but please: "algorithm".
>
>Speaking of spelling, why do some people sometimes say 'optomize'
>instead of 'optimize'?
b/c when some folks say optimize they enunciate it as optomize. Hence
the odd spelling. Infact there are several word in English that may
very well have their spelling changed to "jibe" with current
pronunciation. This happens in living languages.
------------------------------
Date: 01 Aug 2001 01:31:46 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: OT: Writting Perl code that doesn't suck (Was: Strange problem...)
Message-Id: <87k80opyyl.fsf_-_@abra.ru>
G> For more complex tasks than exemplified by my test script
G> below my signature, cgi.pm will slow down a script so much,
G> a visitor will hit her or his escape button then move on
G> to a more interesting and dynamic site. My test script reflects
G> a slow down factor of fifteen, although average is thirteen.
G> No need to comment how much memory cgi.pm wastes, needlessly;
G> my test script is a good indicator of this mindless waste.
G> Toss in strict, warnings, other pragma along with POSIX and
G> other favorite modules these Perl 5 Cargo Cultists around here
G> worship and, you have a virtually useless script.
I really wonder if you ever wrote any Perl application that has size >
100 lines and is maintainable. You deny coding practices that allow to
write maintainable code.
I really wonder if you ever made serious web sites with dynamic
content and big page request rate. Your benchmark is completly
clueles. In *real* CGI application usual bottleneck is file I/O, time
spend waiting for SQL server processing queries and so on. I never
seen creation of one Perl object to be a bottleneck for CGIs and/or
mod_perl handlers.
Usage of tested modules instead of own buggy code do can increase
memory requirments but it is really cheaper to have more RAM then have
downtime because of crappy code.
P.S. Do you know words 'code reusage'? Have you ever wrote anything >
50Kb without using cut-and-paste style?
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: 31 Jul 2001 20:33:24 GMT
From: abigail@foad.org (Abigail)
Subject: Re: perl and Informix
Message-Id: <slrn9me5hq.d4m.abigail@alexandra.xs4all.nl>
miss (north@nmpm.com.my) wrote on MMDCCCLXXXI September MCMXCIII in
<URL:news:3B16152B.ED538A@nmpm.com.my>:
%% Hai all;
%%
%% If I want to using Perl and Informix as my database.What I should
%% install???
Python and DB2.
HTH. HAND.
Abigail
--
sub f{sprintf'%c%s',$_[0],$_[1]}print f(74,f(117,f(115,f(116,f(32,f(97,
f(110,f(111,f(116,f(104,f(0x65,f(114,f(32,f(80,f(101,f(114,f(0x6c,f(32,
f(0x48,f(97,f(99,f(107,f(101,f(114,f(10,q ff)))))))))))))))))))))))))
------------------------------
Date: 31 Jul 2001 15:02:07 -0700
From: doug.mcgrath@us.telegyr.com (Doug McGrath)
Subject: pod question
Message-Id: <a4e10296.0107311402.218c233c@posting.google.com>
> L<name> A link (cross reference) to name
> L<name> manual page
> L<name/ident> item in manual page
> L<name/"sec"> section in other manual page
> L<"sec"> section in this manual page
> (the quotes are optional)
> L</"sec"> ditto
I hope this isn't too stupid of a question, but I can't seem to find
an explanation of what the difference is between "ident" and "sec" in
the above excerpt from perlpod. There's apparently some difference
between an item and a section -- what is it?
Doug McGrath
------------------------------
Date: Tue, 31 Jul 2001 21:26:35 +0200
From: "Stefan Weiss" <weiss@kung.foo.at>
Subject: Re: RegExp
Message-Id: <3b6705ab$1@e-post.inode.at>
"Gerfried Ranner" <ranner@gmx.net> wrote:
> Such a definition can look like this:
> <FRAME name="test1" src="http://www.altavista.com">
> My RegExp pattern is:
> strPattern = "(\<FRAME\s+.*src\s*\=\s*[\""|\']?)(.*)([\""|\']?.*\>)"
>
> THIS WORKS!
> But it returns the whole string, and I would like
> to have http://www.altavista.com to be returned, only.
@results = $html =~ /<frame\s.*?src="([^"]*)/gi;
The array will then contain the locations of all frames in $html.
cheers,
stefan
------------------------------
Date: Tue, 31 Jul 2001 21:31:28 GMT
From: gurm@intrasof.com (Smiley)
Subject: Reporting Questionable Programming Activity
Message-Id: <3b672381.218715906@news1.on.sympatico.ca>
The company I'm working for purchased a Perl CGI Script that turns out
to be seriously faulty - so much so that my boss asked me to
investigate whether there's any international agency or organization
set up that we can report this kind of thing to.
Does anybody know? Thanks :)
------------------------------
Date: Tue, 31 Jul 2001 14:39:53 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: simple IO::Select problem on Win32
Message-Id: <3B6725A9.CB221728@wgn.net>
Allan wrote:
>
> I am looking for a way around the fileevent problem on Win32, by using
> IO::Select to poll for data. The first program below runs as expected
> (helloworld.pl contains the obvious), producing "hello, world"
> my $io = new IO::Handle;
>
> die "Could not attach handle to file"
>
> unless $io->fdopen(fileno($fh), "r");
>
> my $s = IO::Select->new ($io);
You can only select on sockets in Win32 - not just any FH.
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles Mailto:dbe@todbe.com
/ ) /--< o // // http://dbecoll.webjump.com/ (Free site for Perl)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
------------------------------
Date: Tue, 31 Jul 2001 13:06:25 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: sorting by a hash of arrays - how to elegantly extend this code
Message-Id: <3B66F3A1.497AF3C3@home.com>
chris wallace wrote:
>
> In short: my question is about how to (elegantly!) extend the sort
> @new = sort { ${$pos{$a}}[0] <=> ${$pos{$b}}[0] ||
> ${$pos{$a}}[1] <=> ${$pos{$b}}[1]
> } @old;
> to
> @new = sort { ${$pos{$a}}[0] <=> ${$pos{$b}}[0] ||
> ${$pos{$a}}[1] <=> ${$pos{$b}}[1] ||
> ${$pos{$a}}[2] <=> ${$pos{$b}}[2] ||
>
> ....
>
> ${$pos{$a}}[n] <=> ${$pos{$b}}[n] ||
> } @old;
> where n = $#{$pos{$a}} = $#{$pos{$b}}.
I'd do it with a recursive sortsub:
my @new = sort {on_pos(0, $a, $b, \%pos)} @old;
sub on_pos {
my ($i, $a, $b, $r) = @_;
return 0 if $i > $#{$r->{$a}};
return 0 if $i > $#{$r->{$b}};
return($r->{$a}[$i] <=> $r->{$b}[$i] || on_pos($i+1, $a, $b, $r));
}
-mjc
------------------------------
Date: Tue, 31 Jul 2001 11:49:10 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Strange problem...
Message-Id: <3B66FDA5.14EAA5E3@stomp.stomp.tokyo>
Nathan Randle wrote:
(snipped)
Others have resolved your error.
> So anybody know what I'vedone wrong here?
I know what you can do right.
Learning how to both use custom read / parse routines
and cgi.pm, is to your best advantage. Each have good
aspects and each have bad aspects. True Perl programmers
know which is best to use for any given script.
You will quickly learn what you should do and what
you should not do, if you research both methods
carefully and extensively. You will also learn use
of cgi.pm will, on the average, slow down your script
by an average factor of thirteen, compare to a custom
read / parse routine. This is, cgi.pm is an average
of one-thousand-three-hundred percent less efficient
than a custom read / parse routine.
For more complex tasks than exemplified by my test script
below my signature, cgi.pm will slow down a script so much,
a visitor will hit her or his escape button then move on
to a more interesting and dynamic site. My test script reflects
a slow down factor of fifteen, although average is thirteen.
No need to comment how much memory cgi.pm wastes, needlessly;
my test script is a good indicator of this mindless waste.
Toss in strict, warnings, other pragma along with POSIX and
other favorite modules these Perl 5 Cargo Cultists around here
worship and, you have a virtually useless script.
There is a bit wisdom this rogue Perl programmer will cite
very often, "Read, research and do your homework."
Learn both methods well, very well, and you will become
a true Perl programmer rather than...
"Just Another Perl 5 Cargo Cultist."
Godzilla!
--
TEST SCRIPT:
____________
#!perl
print "Content-type: text/plain\n\n";
use Benchmark;
print "Run One:\n\n";
&Time;
print "\n\nRun Two:\n\n";
&Time;
print "\n\nRun Three:\n\n";
&Time;
sub Time
{
timethese (100000,
{
'name1' =>
'$ENV{QUERY_STRING} = "north=north&south=south&east=east&west=west";
$buffer = $ENV{QUERY_STRING};
@checks = split(/&/, $buffer);
foreach $check (@checks)
{
($name, $value) = split(/=/, $check);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
$north = "$FORM{north}";
$south = "$FORM{south}";
$east = "$FORM{east}";
$west = "$FORM{west}";',
'name2' =>
'$ENV{QUERY_STRING} = "north=north&south=south&east=east&west=west";
use CGI;
my $query = new CGI;
$north = $query->param(north);
$south = $query->param(east);
$east = $query->param(south);
$west = $query->param(west);',
} );
}
PRINTED RESULTS:
________________
Run One:
Benchmark: timing 100000 iterations of name1, name2...
name1: 8 wallclock secs ( 8.46 usr + 0.00 sys = 8.46 CPU) @ 11820.33/s
name2: 127 wallclock secs (126.32 usr + 0.00 sys = 126.32 CPU) @ 791.64/s
Run Two:
Benchmark: timing 100000 iterations of name1, name2...
name1: 9 wallclock secs ( 8.79 usr + 0.00 sys = 8.79 CPU) @ 11376.56/s
name2: 127 wallclock secs (126.49 usr + 0.00 sys = 126.49 CPU) @ 790.58/s
Run Three:
Benchmark: timing 100000 iterations of name1, name2...
name1: 8 wallclock secs ( 8.68 usr + 0.00 sys = 8.68 CPU) @ 11520.74/s
name2: 125 wallclock secs (126.27 usr + 0.00 sys = 126.27 CPU) @ 791.95/s
------------------------------
Date: Tue, 31 Jul 2001 22:01:39 +0100
From: "Someone" <slash@dot.n.e.tuk>
Subject: Re: Strange problem...
Message-Id: <20010731.220138.1359512183.794@dot.n.e.tuk>
In article <3B66FDA5.14EAA5E3@stomp.stomp.tokyo>, "Godzilla!"
<godzilla@stomp.stomp.tokyo> wrote:
> Nathan Randle wrote:
>
> (snipped)
>
>
> Others have resolved your error.
>
>
>> So anybody know what I'vedone wrong here?
[childish posturing and horrifically bad attempt at perl]
Man, this girl's setting women's rights back years with every one of her
stupid posts...
Maybe it's a guy pretending to be a girl, for the same reason????
------------------------------
Date: Tue, 31 Jul 2001 19:57:10 +0100
From: Philip Taylor <philip@zaynar.demon.co.uk>
Subject: Re: Telnet/MUD server
Message-Id: <NN8NJHAG+vZ7EwsW@zaynar.demon.co.uk>
Thanks for your response -- just a 'few' points to mention:
In article <3B65FB22.723941FD@earthlink.net>, Benjamin Goldberg
<goldbb2@earthlink.net> writes
>Unless you *need* to do TELNET protocol (all caps because the protocol
>name is an acronym) specific actions, then you can use simple tcp
>sockets, and not worry about the protocol.
I don't need to use the 'real' TELNET protocol -- I just called it
"Telnet" because all the programs which I've connected with are Telnet
terminals (although I've now found that I can use IRC and MUD clients
too)
>You will probably have an easier time of it if you use IO::Socket module
>instead of Socket.
I'm not sure exactly what advantages IO::Socket has over Socket, but
I've found a tutorial/example and converted all my Socket code into
IO::Socket anyway. It appears to just simplify the select/vec/etc
commands, and add a few extra features. It works fine, but I hope it was
worth it :-)
>It's not vec that does the waiting, it's select. vec just puts it into
>a format which select is able to use.
Ah, okay.
>Calling select in your program will tell if the tcp stack has some
>data buffered for that particular tcp connection.
>When you
>call sysread, it copied the data from the tcp buffer into your program's
>memory, then removed from the tcp buffer.
So the Perl program doesn't need to wait while it 'downloads' the data,
which is good :-)
>> # wait for one of the inputs to be ready
>> select($rout=$rin, undef, undef, undef);
>
>This is ok for something like a chat client, but for a MUD, there are
>things happening even when the users aren't typing... for example,
>monsters attacking/moving around, people healing (if they were injured
>and are resting), etc.
It's not actually a MUD (although it functions similarly, with users
just connecting and sending text) -- it's a text conversion of
multiplayer deathmatch games like Quake. A cross between a MUD without
the roleplaying, and an FPS without the graphics...
There are no monsters, no healing over time; the only things which ever
happen are directly due to user input, and so it shouldn't be necessary
to have a timeout.
>If sysread returns <= 0, then the user has closed his connection... told
>telnet to exit (killed the window or whatever). That should be handled
>as a seperate case from the input being "\n".
When processInput ran, it checked whether the length of the data was 0,
and closed the connection if it was. This usually worked, but if the
user has some input buffered (e.g. they begin to type a line of text)
and then disconnect, I suppose it'll just process the beginning of the
line and not notice that they've disconnected... When I wrote the new
IO::Socket version, I've used what you suggested and it works fine.
>> there were some major bugs which I didn't
>> notice, such as the server freezing between when a Microsoft Telnet
>> user started and finished typing
>
>A bug like that indicates that once a user starts typing, you keep
>reading from him until you get a newline. That's a bad thing to do, but
>I'll admit that I don't see where in your code you're doing it.
I fixed it in the code which I posted -- originally, readLine ran a loop
which sysread until it reached a newline. This worked fine when I tested
it with the "CRT" terminal software, which waits until you've finished
the line before sending any data to the server. But some other
terminals, like Microsoft Telnet, send each character as you type them;
this caused readLine to get stuck until that user finished his/her/its
line. I changed it in the code I posted to read one byte at a time and
buffer the input, which fixed the problem.
>Depending on what kind of MUD you want, you might make it so that
>players can *only* attack the bots, not each other.
Since the game design is based on a multiplayer FPS rather than a MUD,
the entire game centers around killing other (human) players. The bots
are only there in case someone logs in and finds nobody else is playing,
so that they can at least attempt to kill something (and the bots will
also be useful for me to test the system with lots of players).
>If you do this, and
>if you make most monsters non-aggressive (ie, they only attack you if
>you attack them), then your mud will be one where it's more or less safe
>for someone to walk away from the keyboard without worrying about
>getting killed.
When you start the game, or when you respawn after dying, you're in a
safe location where you can't be shot. Since an average lifespan is a
few tens of seconds, you are given lots of opportunities to leave the
keyboard :-)
>Also, how smart your bots are is another design decision (it's also
>limited by your ability to code<gg>)
The game is very simple (move and shoot, perhaps changing weapons
occasionally), and based largely on speed (like most FPSs), so the bots
don't need to be particularly smart -- I might have to add some
simulated lag to reduce their speed advantage.
>I would suggest that instead of coding your MUD from scratch, you go
>find the FAQs for reg.games.mud.*, and see if there is already a MUD
>written in perl (or in any other language you know and can code in).
After unsuccessfully searching this newsgroup for anything about "telnet
servers" I tried searching for "MUD" and found what appears to be the
only Perl MUD, imaginatively named PerlMUD. I've downloaded it, and it
looks like it uses a similar connection method to the one I originally
had -- "use Socket", "select", "vec", etc -- and you've said IO::Socket
is better. And anyway, I'm more interested in learning Perl than
creating a fully working game :-)
--
Philip Taylor
philip @ zaynar . demon . co . uk
http://robowarriors.ultrastore.com/legoworld.shtml
-- If the Earth was made of Lego...
------------------------------
Date: 31 Jul 2001 12:23:42 -0700
From: speralta@fidm.com (Salvador)
Subject: Toke::Parser woes...
Message-Id: <727d90fd.0107311123.65a8a7f2@posting.google.com>
I wrote the following bit of code as a test for using TokeParser. The
program should open every file ending with .txt in a given directory,
read the contents of that file into a scalar, then parse the scalar
for a given tag "B", store everything between the given start and end
tag to another variable $text and then print the new variable to
screen. But I've got no joy. Can anyone pinpoint where I've fouled
this up? It seems as though it should be simple enough:
#!/usr/bin/perl
use HTML::TokeParser;
use File::Find;
find(\&parse_dir, "c:/test/parser");
sub parse_dir{
# parse and output tagged text
$filename = $File::Find::name;
if($filename =~ /\.txt$/) {
$parser=HTML::TokeParser->new(\$filename);
while (my $token = $parser->get_tag("B"))
{
my $text = $parser->get_trimmed_text("/B");
}
print "$filename\n";
if ( $text != NULL ){
print $text;
} else {
print "Null value found";
}
}
}
---
C:\test\parser>kat test1.txt
<B>This is a test</B>
<CB>
Insert text here:
</CB>
------------------------------
Date: Tue, 31 Jul 2001 14:32:45 -0400
From: "Eric D." <ericd_@hotmail.com>
Subject: use Cwd
Message-Id: <IMC97.11542$D55.769983@news20.bellglobal.com>
In Windows environment you can use the following statements to get current
directory:
use Cwd;
$current = cwd();
This does NOT work with VAX perl. How do you get the current directory with
VAX perl?
Thanks,
Eric
------------------------------
Date: 01 Aug 2001 00:15:56 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: use Cwd
Message-Id: <87ofq0q2gz.fsf@abra.ru>
ED> In Windows environment you can use the following statements to get current
ED> directory:
ED> use Cwd;
ED> $current = cwd();
ED> This does NOT work with VAX perl. How do you get the current directory with
ED> VAX perl?
AFAIK cwd on many platforms uses shell to get current
directory. Probably there is some misconfiguration on your box (I'm
not sure since I have seen VAX perl). You can try instead:
use Cwd;
$dir = getcwd;
or
use POSIX(getcwd)
$dir = getcwd;
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 1418
***************************************