[21786] in Perl-Users-Digest
Perl-Users Digest, Issue: 3990 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 17 18:05:49 2002
Date: Thu, 17 Oct 2002 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)
Perl-Users Digest Thu, 17 Oct 2002 Volume: 10 Number: 3990
Today's topics:
anonymous scalar refs are read-only -- can someone expl (Dan M)
Re: anonymous scalar refs are read-only -- can someone <uri@stemsystems.com>
Re: Array from String (Tad McClellan)
Re: Array from String <spam@stinks.com>
Re: Array from String (Tad McClellan)
Re: Capitalizing letters in the middle of "word" (Dan Skadra)
Re: Convert Perl script to C program (and Why was this (Tad McClellan)
Re: Convert Perl script to C program (and Why was this <joe+usenet@sunstarsys.com>
Re: Convert Perl script to C program (and Why was this <flavell@mail.cern.ch>
Re: DBD::mysql - $dbh->do() failed (Tad McClellan)
Re: defining subroutines on the fly in a module <bkennedy@hmsonline.com>
Re: defining subroutines on the fly in a module <Tassilo.Parseval@post.rwth-aachen.de>
expanding variables in text strings (Jason Quek)
Re: expanding variables in text strings <ak@freeshell.org.REMOVE>
Re: expanding variables in text strings <alecler@sympatico.ca>
Re: expanding variables in text strings (Tad McClellan)
Re: idea to build an online game <usenet@dwall.fastmail.fm>
Re: mod_perl or fastcgi for performance boost <swen@news.com>
Non-Random Generation of Strings from a Grammar? <david@coppit.org>
Re: Pattern Matching help <krahnj@acm.org>
PCL and PERL?? <justind2@ussonet.net>
problem understanding <harnoor@seas.ucla.edu>
Re: problem understanding <Tassilo.Parseval@post.rwth-aachen.de>
Re: Problems with MSIE in combination with MAC not show <dan@wolf.com>
Re: Problems with MSIE in combination with MAC not show ("Alan J. Flavell")
Python-style unit tests <heather710101@yahoo.com>
Re: Python-style unit tests (John M. Gamble)
Re: Random Character Picker <krahnj@acm.org>
Re: RegExp with a variable (Tad McClellan)
Re: Sending argument to perl <cakes@doentreply.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Oct 2002 14:30:35 -0700
From: boss@moraldecay.com (Dan M)
Subject: anonymous scalar refs are read-only -- can someone explain why?
Message-Id: <8308c5a5.0210171330.5add92e9@posting.google.com>
Can someone explain to me why anonymous scalar refs are read-only when
anonymous array and hash refrences are read-write? I have a pretty
good idea thats it has to do with memory allocation, however I was
hoping someone had a more indepth explanation that will put my curious
mind to rest =)
Thanks!
Dan M.
Example:
my $hash_ref = { one => 2 };
%$hash_ref = (changed => 1);
my $array_ref = [3,4];
@$array_ref = qw(this works);
my $craptastic = '';
my $scalar_ref_1 = \$craptastic;
$$scalar_ref_1 = 'woot, I can change this';
my $scalar_ref_2 = \'';
$$scalar_ref_2 = 'this is read only??'; # 'Modification of a
read-only value attempted' occurs at run time.
------------------------------
Date: Thu, 17 Oct 2002 21:38:39 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: anonymous scalar refs are read-only -- can someone explain why?
Message-Id: <x73cr4690h.fsf@mail.sysarch.com>
>>>>> "DM" == Dan M <boss@moraldecay.com> writes:
DM> Can someone explain to me why anonymous scalar refs are read-only when
DM> anonymous array and hash refrences are read-write? I have a pretty
DM> good idea thats it has to do with memory allocation, however I was
DM> hoping someone had a more indepth explanation that will put my curious
DM> mind to rest =)
DM> my $craptastic = '';
DM> my $scalar_ref_1 = \$craptastic;
DM> $$scalar_ref_1 = 'woot, I can change this';
because there is read/write storage in $craptastic
DM> my $scalar_ref_2 = \'';
DM> $$scalar_ref_2 = 'this is read only??'; # 'Modification of a
DM> read-only value attempted' occurs at run time.
because '' is read only. it can't be expanded since it is not a scalar
variable. it is just a simple null string.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 17 Oct 2002 12:57:20 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Array from String
Message-Id: <slrnaqtug0.3bg.tadmc@magna.augustmail.com>
PinkPuppy <spam@stinks.com> wrote:
> "Brian McCauley" <nobull@mail.com> wrote in message
> news:u9smz5m3mc.fsf@wcl-l.bham.ac.uk...
>> Are you seriously telling us you don't have a computer on which you
>> could install Perl and a webserver?
> I'm saying that I don't own a computer. I can only program on my work
> machine which does not allow me to install software and doesn't have Perl.
> The boss has said... make this happen and make it happen soon.
Tell him he can only have it "late" because you have no
development environment.
If he insists on soon, then tell him you need a local copy
of Perl if you are expected to program in Perl.
Your boss' job is to ensure that his people have the tools they need.
Your boss is not doing _his_ job!
> I'm not trying to waste anyone's
> time,
You are, whether you are trying to or not.
> just trying to keep my job.
at the price of abusing the volunteers who answer questions here.
You are a hair's breadth from landing in lots of killfiles...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 17 Oct 2002 19:11:17 GMT
From: "PinkPuppy" <spam@stinks.com>
Subject: Re: Array from String
Message-Id: <pXDr9.866$XsJ4.51118228@news2.randori.com>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnaqtug0.3bg.tadmc@magna.augustmail.com...
> PinkPuppy <spam@stinks.com> wrote:
> > "Brian McCauley" <nobull@mail.com> wrote in message
> > news:u9smz5m3mc.fsf@wcl-l.bham.ac.uk...
>
> Your boss' job is to ensure that his people have the tools they need.
>
> Your boss is not doing _his_ job!
>
Perhaps, but I don't have the luxury of telling him how to do his job.
>
> > I'm not trying to waste anyone's
> > time,
>
>
> You are, whether you are trying to or not.
>
>
> > just trying to keep my job.
>
>
> at the price of abusing the volunteers who answer questions here.
>
> You are a hair's breadth from landing in lots of killfiles...
>
I thought this was a public place where new and experienced users alike
could get some help. I'm not trying to be rude. If you would prefer, you
can ignore my postings. That is your right. I'm just looking for help.
------------------------------
Date: Thu, 17 Oct 2002 15:01:24 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Array from String
Message-Id: <slrnaqu5ok.3ho.tadmc@magna.augustmail.com>
PinkPuppy <spam@stinks.com> wrote:
> you
> can ignore my postings.
OK.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 17 Oct 2002 11:12:13 -0700
From: dskadra@yahoo.com (Dan Skadra)
Subject: Re: Capitalizing letters in the middle of "word"
Message-Id: <c1bd7661.0210171012.147ff656@posting.google.com>
Thanks for everone's help!
I had actually come up with this shortly after posting the question:
$_ =~ s/(^[a-z])|(_[a-z])/\L$1\L$2/g;
which closly resembled a response I received in an email: (Thanks BTW)
$_ =~ s/(.*)_(.*)/\u$1_\u$2/g;
But I finally settled on John's solution:
$_ =~ s/([a-z]+)/\u$1/g;
Very Elegant. This is why I love Perl. :)
This is actually part of a larger script in win32 that grabs a list of
the users logged into the local domains and creates a html file with
all the users sorted alphabeticly, listing thier computer name and
domain they belong to. This is mainly for our reference, so sorting by
the first letter of the last name works fine. There isn't really a
need to Cap odd names like McDonald or MacDonald, except to learn more
Perl. ;)
Thanks again to everyone who responded.
--------------------
Dan Skadra
dskadra@yahoo.com
'If you can't beat your computer at chess, try kickboxing.'
------------------------------
Date: Thu, 17 Oct 2002 13:16:21 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Convert Perl script to C program (and Why was this group's name changed?)
Message-Id: <slrnaqtvjl.3bg.tadmc@magna.augustmail.com>
Jilla Villa <jillavilla@otakumail.com> wrote:
> Point taken, but this definately goes both ways. I sincerly hope you
> don't think people like Tom Christianson, Tad, et al, have been good
> rolemodels of this preaching? A great example of socially unexceptable
> behavoir is the thread titled "HARASSMENT -- Monthly Autoemail".
I did not participate in that thread.
Do you have an example of where _I_ was rude?
You keep claiming that I frequently am, so it shouldn't be hard
to find one to cite.
Thanks.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 17 Oct 2002 15:46:35 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Convert Perl script to C program (and Why was this group's name changed?)
Message-Id: <m3ptu8u9us.fsf@mumonkan.sunstarsys.com>
"Alan J. Flavell" <flavell@mail.cern.ch> writes:
> On Oct 17, Jilla Villa inscribed on the eternal scroll:
^^^^^^^^^^^
NNTP-Posting-Host: 65.172.197.34
+ http://groups.google.com/groups?selm=3d76abc6.61075808%40news.erols.com
----------------------------------------------------------------------
http://www.winternet.com/~mikelr/flame9.html
+ http://www.winternet.com/~mikelr/flame11.html
Jsut say no.
--
Joe Schaefer "Hain't we got all the fools in town on our side? And hain't
that a big enough majority in any town?"
--Mark Twain
------------------------------
Date: Thu, 17 Oct 2002 20:03:20 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Convert Perl script to C program (and Why was this group's name changed?)
Message-Id: <Pine.LNX.4.40.0210171954390.11027-100000@lxplus071.cern.ch>
On Oct 17, Jilla Villa inscribed on the eternal scroll:
> But the problem is also that the regular visitors of the opera are
> also yelling back at the new comers, causing just as much noise.
You do realise that what you're asking for is - silence?
I hope you're taking careful note of all the respondents who are
following that plan.
When you've collected enough of them, you can tell us whether the
policy is working, OK?
As for your criticism of Tad: I never cease to be astonished at the
degree of patience which he manages to bring to his responses in the
face of demonstrations of advanced cluelessness.
------------------------------
Date: Thu, 17 Oct 2002 12:59:13 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: DBD::mysql - $dbh->do() failed
Message-Id: <slrnaqtujh.3bg.tadmc@magna.augustmail.com>
user <du_bing@hotmail.com> wrote:
> Never mind. I fixed it.
But you are not going to share the solution?
That seems awfully one-way of you.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 17 Oct 2002 14:19:18 -0400
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: defining subroutines on the fly in a module
Message-Id: <KDWdnTBKounKYjOgXTWcog@News.GigaNews.Com>
"Brian McCauley" <nobull@mail.com> wrote in message
news:u9k7khm2rf.fsf@wcl-l.bham.ac.uk...
>
> The eval STRING mechanism should be a last resort. In this case you
> can get by using GLOBs and symrefs (which are the second-to-last
> resort!). [ See other branch of this thread ].
>
> I still think the original problem (the X in this XY) is better
> addressed using an AUTOLOAD sub.
You don't want every typo in a method name to silently fail as it invokes a
get/set method. It also probably easier to grok an explanation using a
simple eval'ed string rather than understanding the magic behind *{$package
. $function} = $coderef, but I could go either way. In the end though, one
may as well use Class::MethodMaker
--Ben Kennedy
------------------------------
Date: 17 Oct 2002 18:37:52 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: defining subroutines on the fly in a module
Message-Id: <aon020$n02$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Ben Kennedy:
> "Brian McCauley" <nobull@mail.com> wrote in message
> news:u9k7khm2rf.fsf@wcl-l.bham.ac.uk...
>>
>> The eval STRING mechanism should be a last resort. In this case you
>> can get by using GLOBs and symrefs (which are the second-to-last
>> resort!). [ See other branch of this thread ].
>>
>> I still think the original problem (the X in this XY) is better
>> addressed using an AUTOLOAD sub.
>
> You don't want every typo in a method name to silently fail as it invokes a
> get/set method. It also probably easier to grok an explanation using a
> simple eval'ed string rather than understanding the magic behind *{$package
> . $function} = $coderef, but I could go either way. In the end though, one
> may as well use Class::MethodMaker
There are always ways around that. You could keep a list of allowed
autoloaded methods. Once one is requested that is not in the list, you
croak().
As for mere accessor-methods (get_* and also set_*) you don't even need
that list since you only need to check (simplified):
my ($method) = $AUTOLOAD =~ /(?:get|set)_(.*)/;
exists $self->{$method} or croak "...";
Even if that is not feasible in the concrete situation, most often these
checks can be made to avoid that typoes slip unnoticed by perl.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Thu, 17 Oct 2002 18:59:47 GMT
From: jason@generationterrorists.com (Jason Quek)
Subject: expanding variables in text strings
Message-Id: <3db503c1.54414003@news.starhub.net.sg>
Hi,
The following works:
# -----------------------------------------------------------------
$one = 'John';
$two = 'Doe';
$three = 'name';
$string = '$one$two is my $three';
$string =~ s/(\$\w+)/$1/eeg;
print $string; # yields 'JohnDoe is my name'
# -----------------------------------------------------------------
However, if I have this:
# -----------------------------------------------------------------
$FORM{'one'} = 'John';
$FORM{'two'} = 'Doe';
$FORM{'three'} = 'name';
$string = '$FORM{\'one\'}$FORM{\'two\'} is my $FORM{\'three\'}';
# -----------------------------------------------------------------
What is the regular expression I should use to match $FORM{'xxx'}?
Any help would be appreciated.
Thank you.
Jason Q.
------------------------------
Date: Thu, 17 Oct 2002 20:50:08 -0000
From: Andreas =?iso-8859-1?Q?K=E4h=E4ri?= <ak@freeshell.org.REMOVE>
Subject: Re: expanding variables in text strings
Message-Id: <slrnaqu8jo.ip5.ak@otaku.freeshell.org>
Submitted by "Jason Quek" to comp.lang.perl.misc:
> Hi,
>
> The following works:
>
> # -----------------------------------------------------------------
> $one = 'John';
> $two = 'Doe';
> $three = 'name';
>
> $string = '$one$two is my $three';
> $string =~ s/(\$\w+)/$1/eeg;
>
> print $string; # yields 'JohnDoe is my name'
> # -----------------------------------------------------------------
>
>
> However, if I have this:
>
> # -----------------------------------------------------------------
> $FORM{'one'} = 'John';
> $FORM{'two'} = 'Doe';
> $FORM{'three'} = 'name';
>
> $string = '$FORM{\'one\'}$FORM{\'two\'} is my $FORM{\'three\'}';
> # -----------------------------------------------------------------
>
> What is the regular expression I should use to match $FORM{'xxx'}?
>
> Any help would be appreciated.
> Thank you.
>
>
>
> Jason Q.
If you use double quotes, the variables will be interpolated as
you assign to $string.
$a = 'aaa';
$b = 'bbb';
$c = '$a$b hello';
print $c, "\n";
outputs
$a$b hello
While
$a = 'aaa';
$b = 'bbb';
$c = "$a$b hello";
print $c, "\n";
results in
aaabbb hello
--
Andreas Kähäri @ New Zealand +------ Have a Unix: netbsd.org
-----------------------------+------ This post ends with :wq
------------------------------
Date: Thu, 17 Oct 2002 17:05:42 -0400
From: Andre <alecler@sympatico.ca>
Subject: Re: expanding variables in text strings
Message-Id: <alecler-1C7357.17054217102002@news1.qc.sympatico.ca>
In article <3db503c1.54414003@news.starhub.net.sg>,
jason@generationterrorists.com wrote:
> The following works:
>
> # -----------------------------------------------------------------
> $one = 'John';
> $two = 'Doe';
> $three = 'name';
>
> $string = '$one$two is my $three';
> $string =~ s/(\$\w+)/$1/eeg;
>
> print $string; # yields 'JohnDoe is my name'
> # -----------------------------------------------------------------
>
>
> However, if I have this:
>
> # -----------------------------------------------------------------
> $FORM{'one'} = 'John';
> $FORM{'two'} = 'Doe';
> $FORM{'three'} = 'name';
>
> $string = '$FORM{\'one\'}$FORM{\'two\'} is my $FORM{\'three\'}';
> # -----------------------------------------------------------------
>
> What is the regular expression I should use to match $FORM{'xxx'}?
You had the right idea in the 2nd example (using a hash as a conversion
table is better), but it should go like this:
my %FORM = (
one => 'John',
two => 'Doe',
three => 'name',
);
my $string = '$one $two is my $three';
$string =~ s/\$(\w+)/exists $FORM{$1} ? $FORM{$1} : "\$$1"/eg;
HTH,
Andre
------------------------------
Date: Thu, 17 Oct 2002 16:16:00 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: expanding variables in text strings
Message-Id: <slrnaqua4g.3q5.tadmc@magna.augustmail.com>
Jason Quek <jason@generationterrorists.com> wrote:
> The following works:
> $string = '$one$two is my $three';
> $string =~ s/(\$\w+)/$1/eeg;
> However, if I have this:
> $string = '$FORM{\'one\'}$FORM{\'two\'} is my $FORM{\'three\'}';
> What is the regular expression I should use to match $FORM{'xxx'}?
$string =~ s/(\$\w+{.*?})/$1/eeg;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 17 Oct 2002 18:06:40 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: idea to build an online game
Message-Id: <Xns92AA8F8BE795Fdkwwashere@216.168.3.30>
[top-posting rearranged; please don't do that]
kit <manutd_kit@yahoo.com> wrote on 17 Oct 2002:
> Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net> wrote in
> message news:<slrnaqsnas.12b.bernard.el-hagin@gdndev25.lido-tech>...
>> In article <1751b2b5.0210162246.742f5fc7@posting.google.com>, kit
>> wrote:
>> > Could any of you please show me how to run a game on one computer and
>> > then it should to connect to another game player's machine?
>>
>> Why, why, why do they keep coming to clpm? What is it about clpm that
>> attracts them so much?
>
> sorry about any inconvenience, if I want to know how to do this stuffs
> with perl, where should I go then? Should I go to other perl news
> group in google? Coz I just want to have a general idea of how to do
> this from some the experts, I don't mean to give a hard time to the
> news group, could you mind tell me how should for this, or direct me
> to another news group if you can?
The reason he complaimed is that clpm seems to get a disproportionate
number of posts asking about things that have little or nothing to do with
Perl, like CGI questions. Your question falls into this category as well.
Games can be written in any programming language. Having one program talk
to another through a network has nothing in particular to do with Perl,
either. You can do these things with Perl, but you can do them with other
programming languages, too.
In addition, the question is so vague it's meaningless. Now if you had
said something like...
"I'm writing a game that <does something>. It needs to send <this game
information> using <this protocol> to another computer. My Perl code is
<cut and paste short snippet of Perl code exhibiting the problem>. When I
run it, I get <this error>. I tried <this> and <that>, but can't figure it
out. Can anyone help me?"
...THEN you probably would have received some useful suggestions. (No
guarantees; this is usenet after all)
For an even more elaborate discussion, see
http://www.tuxedo.org/~esr/faqs/smart-questions.html#intro
At least you got a response. I remember once asking a question here and
no-one responded at all, not even the regulars that probably recognized me
from previous posts. That in itself was a sort of answer: I should have
figured it out on my own.
--
David K. Wall - usenet@dwall.fastmail.fm
"Oook."
------------------------------
Date: Thu, 17 Oct 2002 11:21:14 -0700
From: swen <swen@news.com>
Subject: Re: mod_perl or fastcgi for performance boost
Message-Id: <3DAEFF9A.A0DD0808@news.com>
Tan Nguyen wrote:
> "swen" <swen@news.com> wrote in message news:3DAE20A7.50271AEE@news.com...
> > Hi, I am a perl developer who has been using plain old cgi for creating
> > webapps for awhile now and I want to explore other alternatives in the
> > name of improving the speed of applications.
> >
> > It seems like the biggest bottleneck for my apps is spawning the perl
> > process because I've benchmarked the running times for the entire script
> > and the times are always much smaller than what I have subjectively
> > judged the total page load time to be(e.g. 3 or 4 seconds compared to
> > much less than a second). My benchmark could be flawed I guess, all I'm
> > doing is recording time1 as the first line of code in the script and
> > then recording the time2 and printing the difference as the last two
> > lines of code in the script.
> >
> > Bandwidth is not an issue because I'm testing from a computer on the
> > same lan(and of course static pages load in the blink of an eye). The
> > main feature I care about is performance but I also have the
> > requirements that win2k must be the server platform and I plan to
> > continue using Perl.
> >
> > Also I will be porting existing cgi apps, so I'm somewhat concerned with
> > ease of porting. Also, a straightforward installation would be nice.
> > I'm not interested in any special advantages beyond a performance
> > increase. I would like to restrict this discussion to the topic in the
> > subject line. I am mainly interested in comments about your own
> > personal opinions of either of these(based on experience using them).
> > Links are good too. Thanks.
>
> I've never really looked into fastcgi, so I can't comment on it. However, I
> did have a little bit experience with mod_perl (both pre-2.0 and current
> stable version). Performance boost of mod_perl compared to plain old CGI is
> tremendous provided that you don't have extensively IO bound applications
> such as uploading files etc. Depending the size of your CGI applications,
> you might or might not find it easy to port them to mod_perl. However, if yo
> u go with mod_perl prior to 2.0, you should find things relatively similar
> in both ends. In fact, I tested my stuff as CGI scripts and once it worked,
> I simply plugged it in a driver module with very little change.
Hi, thanks for the reply. I'm not sure what you mean by IO bound. I would
classify most (of my) web applications as very IO bound. There is a lot of
printing to STDOUT and a moderate amount of interaction with the database and I
also write to logs frequently. To what extent and in what way does being IO
bound affect mod_perl performance? Thanks.
------------------------------
Date: Thu, 17 Oct 2002 21:10:23 GMT
From: David Coppit <david@coppit.org>
Subject: Non-Random Generation of Strings from a Grammar?
Message-Id: <20021017170456.A99586-100000@www.provisio.net>
Has anyone written a program which reads in a BNF grammar and enumerates
valid strings in increasing size? i.e.:
EXP = x
EXP = y
EXP = EXP + EXP
EXP = EXP * EXP
this grammar would generate:
x
y
x+x
x+y
y+x
y+y
x*x
x*y
y*x
y*y
x+x+x
...
If not, I'll write it. In this case, has anyone use Parse::RecDescent to
parse BNF grammars? (How's that recursion for ya!) If so, that would sure
help a lot.
Regards,
David
_____________________________________________________________________
David Coppit david@coppit.org
The College of William and Mary http://coppit.org/
One thing the blues ain't... is funny. Stephen Stills, "Black Queen"
------------------------------
Date: Thu, 17 Oct 2002 21:52:30 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Pattern Matching help
Message-Id: <3DAF30E9.8F49D30@acm.org>
Giuseppe wrote:
>
> I have a string of several fields of which two separated 5 spaces.
> The SECOND field of 5 spaces has to be replaced by \n
> The string is:
>
> $test = "LB26 infant brain 1NIB, Soares 10 0.02 #3V4 NIH_MGC_14
> 6 0.04 3582 ST0166 5 16.67"
>
> I tried with $test =~s/ /$2\n/g;
>
> but I get:
>
> LB26 infant brain 1NIB, Soares 10
> 0.02
> #3V4 NIH_MGC_14 6
> 0.04
> 3582 ST0166 5 16.67
>
> instead of:
>
> LB26 infant brain 1NIB, Soares 10 0.02
> #3V4 NIH_MGC_14 6 0.04
> 3582 ST0166 5 16.67
$ perl -le'
$test = "LB26 infant brain 1NIB, Soares 10 0.02 #3V4
NIH_MGC_14 6 0.04 3582 ST0166 5 16.67";
{ local $|;
$test =~ s/( {5})/--$|?$1:"\n"/eg;
}
print $test;
'
LB26 infant brain 1NIB, Soares 10 0.02
#3V4 NIH_MGC_14 6 0.04
3582 ST0166 5 16.67
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 17 Oct 2002 15:38:50 -0500
From: Justin D <justind2@ussonet.net>
Subject: PCL and PERL??
Message-Id: <3DAF1FDA.4060801@ussonet.net>
I'm working on a project that requires printing of documents on
different sizes of paper and some in simplex while others in duplex.
I can make the decisions of what tray to print out of (for the size of
paper) and whether or not to print duplex by the name of the files.
This printer uses pcl (doesn't use postscript though).
This script would be running on a linux box for ease of use/programming.
I'm trying to figure out if I'm looking in the right direction or not
and if so/not could someone who has done anything like this point me
towards some information on the subject?
Any input is much appreciated. Thanks.
------------------------------
Date: Thu, 17 Oct 2002 11:34:12 -0700
From: Arun Harnoor <harnoor@seas.ucla.edu>
Subject: problem understanding
Message-Id: <Pine.GSO.4.44.0210171129370.20915-100000@exposition>
I am a newcomer to perl...i am having trouble understanding what this
does:
@var=qw/ word1 word2 etc/; # this is clear
%var;# is this some declaration /
@var{@var}=();# what is this doing also what does @var{@var=(something) do
Please note that the variable name is the same on all three lines.
Thanks
--Arun
PS: please cc to my email address in the reply
------------------------------
Date: 17 Oct 2002 18:50:44 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: problem understanding
Message-Id: <aon0q4$nom$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Arun Harnoor:
> I am a newcomer to perl...i am having trouble understanding what this
> does:
>
> @var=qw/ word1 word2 etc/; # this is clear
> %var;# is this some declaration /
Not quite. This actually does nothing (in this context, not necessarily
in other spots like last statement of a sub). It would be a declaration
if it were written thusly:
my %var; # a lexical variable, see 'perldoc strict'
> @var{@var}=();# what is this doing also what does @var{@var=(something) do
It's a hash-slice. It is equivalent to:
$var{ $_ } = undef for @var;
So each element in @var is treated as a hash-key and the corresponding
value of the hash %var is set to undef.
Hash- (and also array-) slices are explained in perldata.pod. They are
very useful and allow compact and elegant solutions.
> Please note that the variable name is the same on all three lines.
That's how it looks but they are not the same.
@var{ LIST } ... hash-slice
@var[ LIST ] ... array-slice
The @ is used because a slice is actually a list. Instead, the subscript
'{ ... }' or '[ ... ]' really tell you whether you are accessing a hash
or an array. This distinction is vital:
my %var = ( 1 => 'val1', 2 => 'val2' );
my @var = (1, 2, 3);
my @list;
@list = @var{ 1, 2 }; # @list = ('val1', 'val2')
@list = @var[ 1, 2 ]; # @list = (2, 3)
This should make clear why you need the two differents brackets in the
subscript.
perldata covers that more in detail.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Thu, 17 Oct 2002 14:21:28 -0700
From: Dan Mahoney <dan@wolf.com>
Subject: Re: Problems with MSIE in combination with MAC not showing Perl generated HTML
Message-Id: <fdauqugdhnamv0jc4nou9d6duaq60gaahm@4ax.com>
On Fri, 11 Oct 2002 21:24:20 +0200, "Jan" <jan@nospam.harf.nl> wrote:
>Dear experts,
>
>On a WinNT machine I'm running a webserver which runs a very simple script:
>
>print "Content-type text/html\nPragma: no-cache\n\n";
Should't the two newlines follow the "Content-type", rather than the
"Pragma"?
-------------------------------
Dan Mahoney
dan@wolf.com
------------------------------
Date: Thu, 17 Oct 2002 23:38:24 +0200
From: flavell@mail.cern.ch ("Alan J. Flavell")
Subject: Re: Problems with MSIE in combination with MAC not showing Perl
Message-Id: <Pine.LNX.4.40.0210172328070.11027-100000@lxplus071.cern.ch>
On Oct 17, Dan Mahoney inscribed on the eternal scroll:
> >print "Content-type text/html\nPragma: no-cache\n\n";
>
> Should't the two newlines follow the "Content-type", rather than the
> "Pragma"?
Wouldn't it be useful to find out for yourself, before offering
answers on Usenet? It's not as if there's a world famine of CGI
knowledge, quite apart from the fact that an open specification for
the CGI can be consulted free of charge.
If you didn't spot that the correct solution to the problem was posted
5 days ago, and at least two subsequent postings commented on that
correct solution, there's something desperately wrong with your news
feed too.
[x-posted and f'up suggested, if the damned ciwac automod bot doesn't
go and strip the f'up again]
--
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.
HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html
------------------------------
Date: Thu, 17 Oct 2002 19:50:12 +0000 (UTC)
From: Da Witch <heather710101@yahoo.com>
Subject: Python-style unit tests
Message-Id: <aon49k$os0$1@reader1.panix.com>
The Pythonish way of doing unit tests is to include them in the same
file as the code that is being tested, and testing whether the file
was invoked directly to decide whether to run the tests of not. For
example:
def foo():
# foo stuff
# ...
class bar():
# baz stuff
# ...
# etc. etc.
# -------------------- test program --------------------
def test_1():
# first test
# ...
# ...
def test_n():
# n-th test
# ...
def test():
test_1()
# ...
test_n()
if __name__ == '__main__': test()
One benefit of this scheme is that it keeps the tests and the code
that is being tested together. In contrast, the Perlish approach of
putting the tests in a separate file (or files) seems unnecessarily
cumbersome. What's the benefit of doing it this way?
Thanks,
hk
------------------------------
Date: Thu, 17 Oct 2002 20:11:25 +0000 (UTC)
From: jgamble@ripco.com (John M. Gamble)
Subject: Re: Python-style unit tests
Message-Id: <aon5hd$n82$1@e250.ripco.com>
In article <aon49k$os0$1@reader1.panix.com>,
Da Witch <heather710101@yahoo.com> wrote:
>
>
>
>
>The Pythonish way of doing unit tests is to include them in the same
>file as the code that is being tested, and testing whether the file
>was invoked directly to decide whether to run the tests of not. For
>example:
>
>def foo():
> # foo stuff
> # ...
>class bar():
> # baz stuff
> # ...
>
> # etc. etc.
># -------------------- test program --------------------
>def test_1():
> # first test
> # ...
> # ...
>def test_n():
> # n-th test
> # ...
>def test():
> test_1()
> # ...
> test_n()
>
>if __name__ == '__main__': test()
>
>
>
>One benefit of this scheme is that it keeps the tests and the code
>that is being tested together. In contrast, the Perlish approach of
>putting the tests in a separate file (or files) seems unnecessarily
>cumbersome. What's the benefit of doing it this way?
Extreme lack of clutter. To pick the most trivial example that i can
think of (because the trivial module is mine), consider Games::Maze.
Look at the test scripts. They're very large, and there are a lot
of them, because i have to test these grey-area cases where a single
change might screw things up. Putting all that in the module itself
would make things unnecessarily complex for the hypothetical reader
of that module, who might search for some detail and have to wade
through all the testing code instead.
Also, (here i am wildly speculating, as i am only just now trying
out python), i wonder if there might be a psychological issue too.
Would the hypothetical programmer be more or less likely to add
tests to an already-large module if it just bloats it more? Does
this typical perl module have more tests than it's equivalent
python module, simply because it's easier to add tests without
having the uneasy feeling of code bloat? (This presumes the
tests are separate files in the t/ directory, i personally don't
use the test.pl file for that very reason).
--
-john
February 28 1997: Last day libraries could order catalogue cards
from the Library of Congress.
------------------------------
Date: Thu, 17 Oct 2002 22:00:00 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Random Character Picker
Message-Id: <3DAF32AB.2D35DD56@acm.org>
PinkPuppy wrote:
>
> "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net> wrote in
> message news:aomdkg$6v2$3@korweta.task.gda.pl...
> > In article <LTxr9.831$XsJ4.25034938@news2.randori.com>, PinkPuppy
> > wrote:
> > > Here's what I ended up doing. It's simpler than some of the excellent
> > > suggestions, but it works...
> > >
> > > my @c = ("a","b","c","d","e","f","g","h","i","j","k",
> > > "l","m","n","o","p","q","r","s","t","u","v","w","x",
> > > "y","z","A","B","C","D","E","F","G","H","I","J",
> > > "K","L","M","N","O","P","Q","R","S","T","U","V",
> > > "W","X","Y","Z","0","1","2","3","4","5","6","7","8","9" );
> >
> > If you're gonna do it that way why not make it easier on the eyes:
> >
> > my @c = ('a' .. 'z', 'A' .. 'Z', 0 .. 9);
>
> Well, now that I look at it I can't do that, but perhaps some variation of
> that. I have since removed certain characters from the array such as "l",
> "q", and "0", so it makes using the ".." notation a bit trickier.
Well, at least get rid of the quotes and commas.
my @c = qw( a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9
);
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 17 Oct 2002 12:48:53 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: RegExp with a variable
Message-Id: <slrnaqtu05.3bg.tadmc@magna.augustmail.com>
PinkPuppy <spam@stinks.com> wrote:
> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrnaqtp90.308.tadmc@magna.augustmail.com...
>> PinkPuppy <spam@stinks.com> wrote:
>>
>> > how can I write this expression with abc in a variable?
>>
>> > $test = "abc";
>> > if ($mystring =~ /$test/ ) {
>>
>>
>> What happened when you tried it?
>>
>
> Oh good grief... I didn't of course.
That's what I figured.
Please don't take advantage of us like that, it is demeaning
to be asked to do a machine's work.
> I assumed that it wouldn't work cuz it
> won't work in JavaScript like that.
Perl is not JavaScript, thank Larry. :-)
> I suppose if I actually wanted to look for the
> string literal $test, I'd have to escape the $?
Right. See also:
perldoc -f quotemeta
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 17 Oct 2002 16:56:17 -0400
From: "cakes99" <cakes@doentreply.com>
Subject: Re: Sending argument to perl
Message-Id: <3daf23f9$1_2@nopics.sjc>
Thank you all,
I realized was supposed to use @ARGV; instead of <STDIN>;
makes sense now,
Matt
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnaqte21.284.tadmc@magna.augustmail.com...
> cakes99 <cakes@doentreply.com> wrote:
>
> > How would I go about sending arguments to perl using the shell command.
>
>
> The same way you would go about sending arguments to any
> other program using the shell.
>
>
> > For instance: perl somescript.pl argument
>
>
> That _is_ how you send arguments to perl using the shell.
>
>
> > Perl takes the argument as a file.
>
>
> No it doesn't.
>
> The diamond operator ( <> ) might do that though. Does your
> program use the diamond operator?
>
>
> > Is it possible to pass the argument to
> > the script in a line command without it being passed as a file???
>
>
> Yes.
>
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
------------------------------
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 3990
***************************************