[22000] in Perl-Users-Digest
Perl-Users Digest, Issue: 4222 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 5 18:06:07 2002
Date: Thu, 5 Dec 2002 15:05:14 -0800 (PST)
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, 5 Dec 2002 Volume: 10 Number: 4222
Today's topics:
Re: Cannot get SASL module to work <goldbb2@earthlink.net>
Re: cgi.pm & multiple form widgets of same name <goldbb2@earthlink.net>
Deleting from arrays (OaxacaGangster)
Re: Enumerating %hash keys <goldbb2@earthlink.net>
Re: Enumerating %hash keys <rick.delaney@rogers.com>
Re: forking server and autoflush? <goldbb2@earthlink.net>
Re: forking server and autoflush? <astone@i.net>
Re: Future of Perl as an application server language? (trwww)
Re: Future of Perl as an application server language? (Randal L. Schwartz)
Re: Future of Perl as an application server language? (trwww)
Re: Future of Perl as an application server language? (Simon)
Re: Getting a URL Page <nobull@mail.com>
Re: Getting a URL Page <nobull@mail.com>
Re: help: multi-dimensional hash from flat array <goldbb2@earthlink.net>
Re: Installing perl on removable media - is this feasib <wivey@us.itmasters.com>
Re: Is there a better way of doing this? <parv_fm@emailgroupsWhereElse.com>
Re: Is there a better way of doing this? <tassilo.parseval@post.rwth-aachen.de>
Re: Is there a better way of doing this? <parv_fm@emailgroupsWhereElse.com>
Re: passing data between perl scripts and a module: pro <goldbb2@earthlink.net>
Re: read from a process <goldbb2@earthlink.net>
Re: Scalar variable into indivudals <goldbb2@earthlink.net>
Re: split - more parts than expected <jNoOh.lSePbAeMk@gmx.de>
Too many arguments for open <max@home-werner.de>
Re: Too many arguments for open (Walter Roberson)
Re: Too many arguments for open <max@home-werner.de>
Re: Too many arguments for open <alecler@sympatico.ca>
use Text::ParseWords; problem with ' <stremitz@consultant.com>
wanted: perl code to do JAXB name mapping (LONG) steve.tolkin@fmr.com
What's the correct way to initialize an array to null? (Mike Cambray)
Re: What's the correct way to initialize an array to nu <john@imrie37.fsnet.co.uk>
Re: What's the correct way to initialize an array to nu <tassilo.parseval@post.rwth-aachen.de>
Re: What's the correct way to initialize an array to nu <nobody@dev.null>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 05 Dec 2002 16:29:09 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Cannot get SASL module to work
Message-Id: <3DEFC525.F205D10C@earthlink.net>
tim wrote:
>
> I have a small perl script that uses SMTP Auth and it works fine under
> W2K/ActivePerl 5.6.1. However under RH8/Perl 5.8.0 I'm having
> trouble. I have installed the Authen package correctly, but when I
> run my script I get "No SASL mechanism found". I'm at a loss as to
> what to try - could anyone offer me any pointers?
Read docs (or the source, if it's not in the documentation) of the
module which searches for a SASL mechanism, and find out where it's
looking.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Thu, 05 Dec 2002 17:01:03 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: cgi.pm & multiple form widgets of same name
Message-Id: <3DEFCC9F.356B5160@earthlink.net>
Rodney wrote:
>
> Using CGI.pm to create multiple HTML form widgets of the same name
> (textfields bearing the name $variablename in this case) then using:
> if (param($variablename)) { # check to see if there is anything worth
> reading
> my @list = param($variablename); # read values into list
> }
> solves many problems for me. The trouble I run into is; if the first
> widget named $variablename is vacant, the "if" returns false. For this
> to work then, the user cannot leave the first one blank. Can anyone
> offer a solution to this?
if( my @list = param($variablename) ) {
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: 05 Dec 2002 22:19:21 GMT
From: oaxacagangster@cs.com (OaxacaGangster)
Subject: Deleting from arrays
Message-Id: <20021205171921.14181.00000159@mb-cj.news.cs.com>
When I delete an index from an array, the entry is somehow uninitialized.
I know the actual list size is not reduced by one unless the deleted element is
at
the end of the list.
When I do an " exists $list[4]", it returns true.
According to Programming Perl by Larry Wall, it should return false.
I am using Perl 5.6
Works fine according to the spec for tied lists.
any ideas.....???
------------------------------
Date: Thu, 05 Dec 2002 16:40:52 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Enumerating %hash keys
Message-Id: <3DEFC7E4.1D5C3A17@earthlink.net>
David K. Wall wrote:
[snip]
> while (my($key,undef) = each %hash) {
> print $key, "\n";
> }
There's no need to supply an undef here -- you could do:
while( my($key) = each %hash ) {
print $key, "\n";
}
Just don't leave out the () in 'my($key)' in the while condition -- they
supply list context, and without them, your iteration will stop the
first time $key is "0" or "".
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Thu, 05 Dec 2002 21:46:31 GMT
From: Rick Delaney <rick.delaney@rogers.com>
Subject: Re: Enumerating %hash keys
Message-Id: <m37keoyw95.fsf@cs839290-a.mtth.phub.net.cable.rogers.com>
Benjamin Goldberg <goldbb2@earthlink.net> writes:
> There's no need to supply an undef here -- you could do:
>
> while( my($key) = each %hash ) {
> print $key, "\n";
> }
>
> Just don't leave out the () in 'my($key)' in the while condition -- they
> supply list context, and without them, your iteration will stop the
> first time $key is "0" or "".
Not true in newer perls. It is subject to the same magic as
while (my $line = <>) {
i.e.
while (my $key = each %hash) {
is equivalent to
while (defined(my $key = each %hash)) {
--
Rick Delaney
rick.delaney@rogers.com
------------------------------
Date: Thu, 05 Dec 2002 16:13:31 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: forking server and autoflush?
Message-Id: <3DEFC17B.3DBEE2D9@earthlink.net>
astone wrote:
[snip]
> $main_sock = new IO::Socket::INET (LocalHost => 'freestyle',
> LocalPort => 1200,
> Listen => 15,
> Proto => 'tcp',
> Reuse => 1,
> );
> die "socket could not be created: $!\n" unless ($main_sock);
>
> $main_sock->autoflush(1);
This sets autoflush on the listening socket, which is fairly useless.
> while ($new_sock = $main_sock->accept())
> {
This $new_sock does not have autoflush set on it.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Thu, 05 Dec 2002 23:02:53 GMT
From: astone <astone@i.net>
Subject: Re: forking server and autoflush?
Message-Id: <MPG.1859f938b7ba4517989728@news.pandora.be>
In article <3DEFC17B.3DBEE2D9@earthlink.net>, goldbb2@earthlink.net
says...
> astone wrote:
> [snip]
> > $main_sock = new IO::Socket::INET (LocalHost => 'freestyle',
> > LocalPort => 1200,
> > Listen => 15,
> > Proto => 'tcp',
> > Reuse => 1,
> > );
> > die "socket could not be created: $!\n" unless ($main_sock);
> >
> > $main_sock->autoflush(1);
>
> This sets autoflush on the listening socket, which is fairly useless.
>
> > while ($new_sock = $main_sock->accept())
> > {
>
> This $new_sock does not have autoflush set on it.
you're absolutely right, i noticed that only now. i have tried it
the other way round too though, without success.
anyway, i got the job done by my slackware box, so problem solved.
thanks for your answer.
dk
------------------------------
Date: 5 Dec 2002 12:03:59 -0800
From: toddrw69@excite.com (trwww)
Subject: Re: Future of Perl as an application server language?
Message-Id: <d81ecffa.0212051203.1073c54e@posting.google.com>
simonf@simonf.com (Simon) wrote in message news:<3226c4d3.0212041132.538947eb@posting.google.com>...
<snip />
>
> > > I am developing intranet applications in Perl, borrowing and writing
> > > code that slowly becomes an application server framework. I am sure
> > > lots of people do the same thing in Perl. However, I think the lack of
> > > standards is killing us.
> >
> > Not where I'm from. To be fair, the phrases you use are not
> > well-defined[2] to me...
>
> See - another example of terminology not quite established in the Perl
> world. No Java programmer will question what "application server"
> means - they are long used to its commong meaning of "second-tier
> software framework".
>
> > I'd be interested in some concrete examples of
> > what you're doing and what problems you face.
>
> Object-relational persistence, of course. There are several tools
> listed at
> http://poop.sourceforge.net/ , but compare this to the number of
> similar Java tools: http://c2.com/cgi-bin/wiki?ObjectRelationalToolComparison
> . I may be contradicting myself, because more tools means fewer
> standards, but in this case, I think, the number of tools corresponds
> to the popularity of a concept. There are commercial Java OORDB tools
> out there, but no commercial Perl tools.
I would think this is because perl is not a commercial language.
> More interesting is the question of web-object persistence. When the
> CGI parameters are received, some of them must be ignored, some should
> be accepted to override the values in the database, but some other may
> only be used for creation, not updating. Plus, the set of accepted
> parameters can vary depending on which user is logged in. Plus, I may
> need to create more than one object from a single CGI hash. I have not
> seen a decent abstraction layer for this at all.
For large inter/intranet apps, IMO CGI is not an option. You are
looking for object persistence. Its not built in to the CGI framework,
so you have to find sometimes different ways of emulating it. My
solution was to find a framework that has persistence built in.
http://groups.google.com/groups?selm=d81ecffa.0210081039.610de474%40posting.google.com
has a discussion of how I use apache with mod_perl enabled to
_get_the_job_done_(tm). The context of the discussion was a question
about how to develop web apps faster.
<snip />
>
> Operation dispatch - how to invoke different methods in different
> classes based on the CGI parameters. Currently I am using parameters
> called 'isa' and 'op', but what if I need to specify more than one
> operation? Nothing fancy here, and a lot of applications do this
> already, but different people use different parameter names.
I think your problem is not lack of solutions, but so many solutions
that you are dismissing them as not viable and sticking to what works,
aka plain ol CGI.
mod_perl, Template::Toolkit, Mason, Embperl, ASP, and this is only a
fraction of the list even if you exclude the newer services that have
been made possible by XML (like AxKit).
OTOH, I havent see you mention any of these tools, so perhaps you may
not be aware of them, in which case I suggest exploring perl culture
and convention a bit more.
My biggest ( and probably only ) complaint about perl is that there
are too many ways to _get_the_job_done_(tm). But thats a pretty nice
complaint to be able to have about a programming language. Its alot
faster to browse CPAN for all applicable solutions, try them all, glue
them together and/or modify one or more than it is to develop an
untested solution from scratch.
> I am not even going to mention thread safety issues, transactions,
> handling JARs and their dependencies, where Java is way ahead.
Im no expert in this area, but I would think that the web and database
servers are mostly responsible for at least the first two, in which
case I can happily continue extending my applications with the Apache
API.
<snip />
> Err... of course I use DBI. However, pretty much everybody agreed at
> the conference that having raw SQL in your code is bad design. It may
> be fine for a two-page script, but is unacceptable in an enterprise
> application. A good persistence layer is a must. IMHO omitted
> deliberately.
This paragraph says two different things, I think. As has been
mentioned already, If there is raw SQL in the code, thats the
programmers fault, not that of the language.
HTTP has no persistence layer. Therefore, any language you use to
develop applications delivered via HTTP can do no better than emulate
one. Both perl and java have excellent persistence emulation. Java has
one way to do it, perl has many different ways it can be done.
> > > Do you know that coarse-grained session beans give you better
> > > performance than any kind of entity beans, even with caching?
This is jargon. If you look through other posts on c.l.p.m. or even
perl.beginners and perl.beginners.cgi on nntp.perl.org you wont find
much jargon.
Theres only one way to get persistence over http. Somehow tie an id to
a client, and be sure they return the id with each request. Then tie
that id with either a record in a database or a persistent data
structure in memory on the server.
To get this back on topic, perl has an excellent past, present AND
future as an application server language. The proof?
http://perl.oreilly.com/news/success_stories.html
Todd W.
------------------------------
Date: 05 Dec 2002 12:57:14 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Future of Perl as an application server language?
Message-Id: <86lm345glx.fsf@red.stonehenge.com>
>>>>> "Simon" == Simon <simonf@simonf.com> writes:
Simon> I have recently went to the Software Development Conference/Expo in
Simon> Boston and was faced with the fact that Java seems to be the language
Simon> of choice for serious web applications.
Java is the language of choice of people who put on conferences and
pay for advertising. The marketplace is a strange beast. Nearly
everyone I know who has had a serious evaluation of Perl vs Java and
has been free to choose, has gotten the real work done in Perl. But
in those shops where the management "manages by magazine", Java has
been forced down the throats of those poor souls. Just like M$
products. :)
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 5 Dec 2002 13:16:35 -0800
From: toddrw69@excite.com (trwww)
Subject: Re: Future of Perl as an application server language?
Message-Id: <d81ecffa.0212051316.59406e54@posting.google.com>
simonf@simonf.com (Simon) wrote in message news:<3226c4d3.0212030947.556f7ed1@posting.google.com>...
<snip />
>
> Do you know that coarse-grained session beans give you better
> performance than any kind of entity beans, even with caching? This is
> just a condensed form of saying that fetching objects from the
> database is best done in one fell swoop into some kind of data
> structure, rather than going to the database every time an object is
> created. Nothing groundbreaking, but the Java folks have enough common
> terminology to pack more bandwidth into the conversation, which makes
> it easier to pursue higher level concepts.
Some of this paragraph was snipped in the post I replied to so I
missed most of this paragraph. Yeah, I agree with you 100% about
fetching all data at one time, and this is basically what XML is all
about. But awareness of this concept dosent make Java special. Load
request specific data into a DOM, XPath, or SAX object, or any type of
data structure you please. Nothing language specific.
> I wonder what the community thinks about an emergence of some kind of
> standard for Perl application servers. Is this possible/desirable at
> all? Who would have the authority to push it? Is there something close
> enough to a standard which is not well known?
A mod_perl enabled apache web server is what you are looking for. Very
documented and very stable. Extensible and configurable, even
dynamically, in any way you could dream, and some you never imagined.
> Yes, there are a few projects listed on
> http://perl.apache.org/products/app-server.html . However, only Bivio
> and OpenInteract seem to be comprehensive enough. Bivio is new, and
> OpenInteract is mentioned once in a while in the newsgroups, but its
> Sourceforge project has only three developers. There is the barely
> alive PAS project, plus a great paper about Camelot (but with no
> implementation to follow). Pretty bleak, I would say. :(
>
I had a look at your link to:
http://c2.com/cgi-bin/wiki?ObjectRelationalToolComparison
from a following post. I didnt see anything that was more
comprehensive than any perl based tool. Some products were nothing
more than an abstract layer to a database so that the tables
automatically look like an object. They even wanted money for some of
them.
Take a look at http://search.cpan.org/modlist/Database_Interfaces/DBIx
The one that cought my eye immdiately was DBIx::Lookup::Field which
will "Create a lookup hash from a database table". Ive also used
Tie::DBI and DBIX::RecordSet which both work fine.
Perl and shrink wrap dont mix ;0)
Todd W.
------------------------------
Date: 5 Dec 2002 14:54:37 -0800
From: simonf@simonf.com (Simon)
Subject: Re: Future of Perl as an application server language?
Message-Id: <3226c4d3.0212051454.6d6aee6a@posting.google.com>
Joe,
Thank you for your response.
Joe Schaefer <joe+usenet@sunstarsys.com> wrote in message
> Then be sure to check out Jakarta: <URL:http://jakarta.apache.org/>.
> They've got a bunch of cool projects to build on, and they could
> use some fresh new Perl blood injected into their community. ;-)
I don't even know how to classify my blood. :) Probably Smalltalk.
:)))
My strictly object-oriented way of coding in Perl will probably
disgust some hard-core hackers... :)
> [...]
>
> > Perhaps this is a wrong group to bring up these issues. I will
> > appreciate suggestions for a more appropriate forum.
>
> p5ee at perl.org (it's a mailing list).
Yes!!!! That's what I was looking for!
Simon
------------------------------
Date: 05 Dec 2002 19:18:43 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Getting a URL Page
Message-Id: <u9d6ogtgto.fsf@wcl-l.bham.ac.uk>
kasp@epatra.com (Kasp) writes TOFU:
> What should I do now?
Stop posting TOFU before your rudeness causes you to be killfiled by
the most helpfull and knowledgible people arround here. (Not me, I'm
not a plonker, at least not in that sense).
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 05 Dec 2002 19:24:42 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Getting a URL Page
Message-Id: <u97keotgjp.fsf@wcl-l.bham.ac.uk>
kasp@epatra.com (Kasp) writes:
> However when I try to use LWP, I get the error "Can't locate
> LWP/Simple.pm in @INC".
>
> Can someone tell me what I have to do to get rid of this error and get
> the code working?
If you look up that error in the reference manual this is what you find:
(F) You said to "do" (or "require", or "use") a file
that couldn't be found. Perl looks for the file in all
the locations mentioned in @INC, unless the file name
included the full path to the file. Perhaps you need
to set the PERL5LIB or PERL5OPT environment variable
to say where the extra library is, or maybe the script
needs to add the library name to @INC. Or maybe you
just misspelled the name of the file. See the require
entry in the perlfunc manpage and the lib manpage.
Actually that's not much help because the reason "You may not have
installed the module" is considered too obvious to mention.
Install LWP. See FAQ: "What modules and extensions are available for Perl?..."
> Thanks.
There's little point saying "Thanks" if you are going to rudely spit
TOFU in our faces.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 05 Dec 2002 16:58:10 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: help: multi-dimensional hash from flat array
Message-Id: <3DEFCBF2.35F53A89@earthlink.net>
Simon Hardy-Francis wrote:
>
> Just for completeness then here's the compact version without any
> loops:
>
> my $var = "a-b-c-d-e";
> my %h;
> (my $statement = qq[\$h{$var}=823]) =~ s/-/}{/g;
The /g on your s/// performs a loop.
> eval $statement;
Out of curiousity, what happens if someone has a string like:
'a-b-system "rm /*"-c-d'
> warn() if $@;
> print $h{a}{b}{c}{d}{e};
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Thu, 5 Dec 2002 16:16:52 -0600
From: "William" <wivey@us.itmasters.com>
Subject: Re: Installing perl on removable media - is this feasible?
Message-Id: <wgGdnXsdtd7RTXKgXTWcpg@giganews.com>
"Andras Malatinszky" <nobody@dev.null> wrote in message
news:3DEF83F9.6060604@dev.null...
>
> This is a slightly different approach, but wouldn't Perl2Exe take care of
your problem?
>
>
> http://www.indigostar.com/perl2exe.htm
>
Hmm, I saw that mentioned somewhere, but the 'exe' made me
think Windows only and I didn't follow it up. I'll have to
have a look at it. Thanks. -Wm
------------------------------
Date: Thu, 05 Dec 2002 19:55:25 GMT
From: parv <parv_fm@emailgroupsWhereElse.com>
Subject: Re: Is there a better way of doing this?
Message-Id: <slrnauvbuo.a3c.parv_fm@localhost.holy.cow>
in message <u9k7iotitz.fsf@wcl-l.bham.ac.uk>,
wrote Brian McCauley ...
> "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de> writes:
>
>> my @empty;
>> $#empty = 99;
>>
>> It sets the initial capacity to 100 (by specifying the index of the last
>> element to 99). Elements will be undef then.
>
> Strictly speaking they are not only undef but non-existant.
^ ^ ^ ^ ^ ^
^ ^ ^ ^ ^ ^
brian, did you mean that array elements are both undef and
non-existatnt? i am disoriented due to possibly missing "also" in
between "but" & "non-existant" (at the end).
- parv
--
please don't send me private e-mail.
if you must, do away w/ WhereElse in the address.
------------------------------
Date: 5 Dec 2002 20:18:15 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Is there a better way of doing this?
Message-Id: <asoca7$23i$1@nets3.rz.RWTH-Aachen.DE>
Also sprach parv:
> in message <u9k7iotitz.fsf@wcl-l.bham.ac.uk>,
> wrote Brian McCauley ...
>
>> "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de> writes:
>>
>>> my @empty;
>>> $#empty = 99;
>>>
>>> It sets the initial capacity to 100 (by specifying the index of the last
>>> element to 99). Elements will be undef then.
>>
>> Strictly speaking they are not only undef but non-existant.
> ^ ^ ^ ^ ^ ^
> ^ ^ ^ ^ ^ ^
> brian, did you mean that array elements are both undef and
> non-existatnt? i am disoriented due to possibly missing "also" in
> between "but" & "non-existant" (at the end).
That'd indeed a logical contradiction. It's different. When you say
my @array;
$#array = 9;
this is roughly similar to C's:
unsigned char array[9];
That is you create an array with an initial capacity of 10 elements.
In the C case this is then also its final capacity so you can only store
for instance a string with length of nine plus terminating \0 in it. In
Perl you can still set the 11th element since it grows dynamically.
What Brian meant is a general concept in Perl: accessing a non-existant
element of an array (or hash value) wont trigger a run-time error (like
segfault or so). Instead it is treated as undef. But still you can
distinguish between undef and not existant:
my @array;
exists $array[0]; # no, does not exist
defined $array[0]; # no, not defined, therefore undef
I am sure you already sense how marginal this difference is. And since
exists() is only seldom used on arrays it might not even matter at all.
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, 05 Dec 2002 20:49:22 GMT
From: parv <parv_fm@emailgroupsWhereElse.com>
Subject: Re: Is there a better way of doing this?
Message-Id: <slrnauvf5u.ba8.parv_fm@localhost.holy.cow>
in message <asoca7$23i$1@nets3.rz.RWTH-Aachen.DE>,
wrote Tassilo v. Parseval ...
> Also sprach parv:
>
>> in message <u9k7iotitz.fsf@wcl-l.bham.ac.uk>,
>> wrote Brian McCauley ...
>>
>>> "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de> writes:
>>>
>>>> my @empty;
>>>> $#empty = 99;
>>>>
>>>> It sets the initial capacity to 100 (by specifying the index of
>>>> the last element to 99). Elements will be undef then.
>>>
>>> Strictly speaking they are not only undef but non-existant.
>> ^ ^ ^ ^ ^ ^
>> ^ ^ ^ ^ ^ ^
>> brian, did you mean that array elements are both undef and
>> non-existatnt? i am disoriented due to possibly missing "also"
>> in between "but" & "non-existant" (at the end).
...
> What Brian meant is a general concept in Perl: accessing a
> non-existant element of an array (or hash value) wont trigger a
> run-time error (like segfault or so). Instead it is treated as
> undef.
that's what i thought. my problem was not in understanding what
perl does but in parsing English-with-capital-E.
> But still you can distinguish between undef and not
> existant:
no problem there.
- parv
--
please don't send me private e-mail.
if you must, do away w/ WhereElse in the address.
------------------------------
Date: Thu, 05 Dec 2002 16:46:31 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: passing data between perl scripts and a module: probably a basic question
Message-Id: <3DEFC937.7EC518BB@earthlink.net>
Tad McClellan wrote:
[snip]
> > @list = sort (@list); @list = reverse (@list);
>
> Why not just sort it into descending order in the first place
> rather than reversing the results of an ascending order sort?
>
> @list = sort {$b cmp $a} @list;
Depending on the size of the list, and the version of perl, it *may* be
faster to do:
@list = reverse sort @list;
Even if it's not faster, it's certainly fewer characters, and is
slightly easier to read and understand.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Thu, 05 Dec 2002 16:35:55 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: read from a process
Message-Id: <3DEFC6BB.B9B69917@earthlink.net>
Robert Szczygiel wrote:
>
> Sunil wrote:
> > All,
> > I have got the following routine which take a arbitrary sql
> > script and executes it after connecting to a oracle DB.
> [...]
> > Any Ideas?
>
> perldoc -m IPC::open3
>
> Example for running perl script:
>
> open3( \*WRH, \*RDH, \*ERH, "perl",$pname,@args);
> close( WRH );
> my @stdout = <RDH>;
> my @stderr = <ERH>;
What happens if the program prints so much to it's stderr that it fills
up the pipe? Writing will block, and the process will go to sleep until
something reads from the other end of the pipe. But, since your parent
process is first reading from the stdout, not the stderr, of the child
process, it will block, waiting for EOF, and go to sleep. Since both
processes are asleep, waiting for the other to do IO, the result is
deadlock. Oops.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Thu, 05 Dec 2002 16:50:06 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Scalar variable into indivudals
Message-Id: <3DEFCA0E.F9739A60@earthlink.net>
Geezer From The Freezer wrote:
>
> I have a scalar variable that contains this:-
>
> 8 packets transmitted, 8 packets received, 0% packet loss round-trip
> (ms) min/avg/max = 2/2/3
>
> I need to get the following into individual variables:-
>
> 0% (as 0)
> 2/2/3 (I need the middle value 2)
my ($loss, $avg) = ( $data =~ /\d+/g )[2, 4];
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Fri, 29 Nov 2002 13:19:39 +0100
From: "Johannes Lebek" <jNoOh.lSePbAeMk@gmx.de>
Subject: Re: split - more parts than expected
Message-Id: <asolq7$mfb$06$1@news.t-online.com>
Thank you very much, Jeff, Bernard, and Dave!
I've learned: Using functions the way they are intended, everything works
fine! ;-)
I appreciate these numerous responses very much!
Johannes
------------------------------
Date: Thu, 5 Dec 2002 22:15:07 +0100
From: "Max J. Werner" <max@home-werner.de>
Subject: Too many arguments for open
Message-Id: <rkfosapm9.WHATTHEFUCK.ln@31427-werner.news.cis.dfn.de>
Hi,
I'm running perl v5.6.1 on i386-linux here.
Someone who runs perl v5.005_02 on i386-netbsd has some problems with a
perl script which I've written:
Too many arguments for open at /net/u/1/d/dman/bin/maxstat line 153,
near "".old") "
Too many arguments for open at /net/u/1/d/dman/bin/maxstat line 201,
near "]) "
Execution of /net/u/1/d/dman/bin/maxstat aborted due to compilation
errors.
Lines 153 and 201 look like this:
153:
open(FILEOLD, '>', $ARGV[0].".old") || usage(1, "Could not open
$ARGV[0].old: $!");
201:
open(FILE, '>', $ARGV[0]) || usage(1,"Could not open $ARGV[0] for
writing: $!");
Why don't I have these errors but he does? And what do these errors mean?
TIA,
Max
--
fortune says:
"On a normal ascii line, the only safe condition to detect is a 'BREAK'
- everything else having been assigned functions by Gnu EMACS."
(By Tarl Neustaedter)
------------------------------
Date: 5 Dec 2002 21:39:13 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: Too many arguments for open
Message-Id: <asoh21$700$1@canopus.cc.umanitoba.ca>
In article <rkfosapm9.WHATTHEFUCK.ln@31427-werner.news.cis.dfn.de>,
Max J. Werner <max@home-werner.de> wrote:
:I'm running perl v5.6.1 on i386-linux here.
:Someone who runs perl v5.005_02 on i386-netbsd has some problems with a
:perl script which I've written:
:Too many arguments for open at /net/u/1/d/dman/bin/maxstat line 153,
:near "".old") "
:open(FILEOLD, '>', $ARGV[0].".old") || usage(1, "Could not open
:$ARGV[0].old: $!");
Older perls do not have the 3-argument form of 'open'.
(Or at least they don't document it.) Try
open FILEOLD, ">$ARGV[0].old" or usage(1, "Could not open $ARGV[0].old: $!");
--
Reviewers should be required to produce a certain number of
negative reviews - like police given quotas for handing out
speeding tickets. -- The Audio Anarchist
------------------------------
Date: Thu, 5 Dec 2002 22:50:01 +0100
From: "Max J. Werner" <max@home-werner.de>
Subject: Re: Too many arguments for open
Message-Id: <9mhosa44a.WHATTHEFUCK.ln@31427-werner.news.cis.dfn.de>
Max J. Werner <max@home-werner.de> wrote:
> Hi,
> I'm running perl v5.6.1 on i386-linux here.
> Someone who runs perl v5.005_02 on i386-netbsd has some problems with a
> perl script which I've written:
>
> Too many arguments for open at /net/u/1/d/dman/bin/maxstat line 153,
> near "".old") "
> Too many arguments for open at /net/u/1/d/dman/bin/maxstat line 201,
> near "]) "
> Execution of /net/u/1/d/dman/bin/maxstat aborted due to compilation
> errors.
>
> Lines 153 and 201 look like this:
> 153:
> open(FILEOLD, '>', $ARGV[0].".old") || usage(1, "Could not open
> $ARGV[0].old: $!");
>
> 201:
> open(FILE, '>', $ARGV[0]) || usage(1,"Could not open $ARGV[0] for
> writing: $!");
Okay,
I have tested that with Perl v5.005_03 on i386-freebsd and I get the
same error. When I modify the lines it works:
open(FILEOLD, ">".$ARGV[0].".old") || usage(1, "Could not open
$ARGV[0].old: $!");
open(FILE, ">".$ARGV[0]) || usage(1,"Could not open $ARGV[0] for
writing: $!");
Is the 3-argument form not implemented in Perl <v5.6.1?
Max
--
fortune says:
"Besides, I think [Slackware] sounds better than 'Microsoft,' don't you?"
(By Patrick Volkerding)
------------------------------
Date: Thu, 05 Dec 2002 17:12:32 -0500
From: Andre <alecler@sympatico.ca>
Subject: Re: Too many arguments for open
Message-Id: <alecler-7AA970.17123205122002@news1.qc.sympatico.ca>
In article <9mhosa44a.WHATTHEFUCK.ln@31427-werner.news.cis.dfn.de>, "Max
J. Werner" <max@home-werner.de> wrote:
[...]
> I have tested that with Perl v5.005_03 on i386-freebsd and I get the
> same error. When I modify the lines it works:
> open(FILEOLD, ">".$ARGV[0].".old") || usage(1, "Could not open
> $ARGV[0].old: $!");
> open(FILE, ">".$ARGV[0]) || usage(1,"Could not open $ARGV[0] for
> writing: $!");
>
> Is the 3-argument form not implemented in Perl <v5.6.1?
The 3-arg form of open() came with 5.6.0.
Andre
------------------------------
Date: Thu, 05 Dec 2002 15:34:21 -0500
From: Alexander Stremitzer <stremitz@consultant.com>
Subject: use Text::ParseWords; problem with '
Message-Id: <3DEFB84D.1070308@consultant.com>
I am using the library Text::ParseWords to parse a TAB separated file.
open (RIS,"<ris.good");
while (<RIS>) {
chop($_);
my $RIS_LINE = $_;
push @RISLIST, [ quotewords ('\t', 0, $RIS_LINE) ];
My data look something similar to
62008286 644719 EDWARDS MONICA D 1958.07.27
181490 "GOSNELL, KERMIT, MD"
62155755 567426 D'ALONZO WILL M
1914.04.07 181489 "GENTCHOS, ERNEST"
The first line works fine, but the ' character in the name of the second
line causes problems. I don't know why Excel does not qoute the data
when extracted from a SQL database via MS Query. Not all fields have the
same length.
How can I work around this issue ?
Any help or suggestions will be greatly appreciated.
Thanks,
Alex
--
All man's miseries derive from not being able to sit quietly in a room alone. (Pascal)
------------------------------
Date: 04 Dec 2002 09:58:48 -0500
From: steve.tolkin@fmr.com
Subject: wanted: perl code to do JAXB name mapping (LONG)
Message-Id: <u4r9t25lj.fsf@fmr.com>
Summary: I am looking for a program to do name mappping
as specified in Appendix C of the JAXB (Java XML Binding) spec.
This for example will map from foo_bar to fooBar etc.
Although they talk about Java and XML names, this
mapping applies to many other programming languages too.
In particular databases typically use the underscore
character as the separator, and so this program would
would be very useful for that translation.
Note the careful treatment that locates the word break in front
of an upper case letter followed by a lowercase letter
e.g. FOOBar becomes FOO_BAR in the mapping to a constant.
Details:
I quote from the following document, downloadable from Sun. I only
quoted the first part of Appendix C - mapping XML name to Java
Identidier. I also want a program to do the reverse mapping. It was
in file jaxb-0_7-prd-spec.pdf. After copying the text and pasting it
as plain ASCII I had to slightly edit this file, e.g. to align the
tables using spaces, add newlines, etc. I lost many of the bullets in
the original and did not manually add them all back.
<quote from = "
The Java(TM) Architecture for XML Binding (JAXB) Public Draft, V0.7
September 12, 2002 ">
C.1 Overview
This section provides default mappings from:
XML Name to Java identifier
Model group to Java identifier
Namepsace URI to Java package name
C.2 The Name to Identifier Mapping Algorithm
Java identifiers typically follow three simple, well-known
conventions:
Class and interface names always begin with an upper-case letter. The
remaining characters are either digits, lower-case letters, or
upper-case letters. Upper-case letters within a multi-word name serve
to identify the start of each non-initial word, or sometimes to stand
for acronyms.
Method names and components of a package name always begin with a
lower-case letter, and otherwise are exactly like class and interface
names.
Constant names are entirely in upper case, with each pair of words
separated by the underscore character (‘_’, \u005F, LOW LINE).
XML names, however, are much richer than Java identifiers: They may
include not only the standard Java identifier characters but also
various punctuation and special characters that are not permitted in
Java identifiers. Like most Java identifiers, most XML names are in
practice composed of more than one natural-language word. Non-initial
words within an XML name typically start with an upper-case letter
followed by a lower-case letter, as in Java, or are prefixed by
punctuation characters, which is not usual in Java and, for most
punctuation characters, is in fact illegal.
In order to map an arbitrary XML name into a Java class, method, or
constant identifier, the XML name is first broken into a word
list. For the purpose of constructing word lists from XML names we use
the following definitions:
A punctuation character is one of the following:
* A hyphen (’-’, \u002D, HYPHEN-MINUS),
* A period (‘.’, \u002E, FULL STOP),
* A colon (’:’, \u003A, COLON),
* An underscore (’_’, \u005F, LOW LINE),
* A dot (‘.’, \u00B7, MIDDLE DOT),
* \u0387, GREEK ANO TELEIA,
* \u06DD, ARABIC END OF AYAH, or
* \u06DE, ARABIC START OF RUB EL HIZB.
These are all legal characters in XML names.
A letter is a character for which the Character.isLetter method
returns true, i.e., a letter according to the Unicode standard. Every
letter is a legal Java identifier character, both initial and
non-initial.
A digit is a character for which the Character.isDigit method returns
true, i.e., a digit according to the Unicode Standard. Every digit is
a legal non-initial Java identifier character.
A mark is a character that is in none of the previous categories but
for which the Character.isJavaIdentifierPart method returns true. This
category includes numeric letters, combining marks, non-spacing marks,
and ignorable control characters.
Every XML name character falls into one of the above categories. We
further divide letters into three subcategories:
An upper-case letter is a letter for which the Character.isUpperCase
method returns true,
A lower-case letter is a letter for which the Character.isLowerCase
method returns true,and
All other letters are uncased.
An XML name is split into a word list by removing any leading and
trailing punctuation characters and then searching for word breaks. A
wordbreak is defined by three regular expressions: A prefix, a
separator, and a suffix. The prefix matches part of the word that
precedes the break, the separator is not part of any word, and the
suffix matches part of the word that follows the break. The word
breaks are defined as:
Table 3-1 XML Word Breaks
Prefix Separator Suffix Example
[^punct] punct+ [^punct] foo|--|bar
digit [^digit] foo22|bar
[^digit] digit foo|22
lower [^lower] foo|Bar
upper upper lower FOO|Bar
letter [^letter] Foo|\u2160
[^letter] letter \u2160|Foo
(The character \u2160 is ROMAN NUMERAL ONE, a numeric letter.)
After splitting, if a word begins with a lower-case character then its
first character is converted to upper case. The final result is a word
list in which each word is either
* A string of upper- and lower-case letters, the first character of
which is upper case,
* A string of digits, or
* A string of uncased letters and marks.
Given an XML name in word-list form, each of the three types of Java
identifiers is constructed as follows:
* A class or interface identifier is constructed by concatenating the
words in the list,
* A method identifier is constructed by concatenating the words in the
list. A prefix verb (get, set, etc.) is prepended to the result.
* A constant identifier is constructed by converting each word in the
list to upper case; the words are then concatenated, separated by
underscores.
This algorithm will not change an XML name that is already a legal and
conventional Java class, method, or constant identifier, except
perhaps to add an initial verb in the case of a property access
method.
Example
Table 3-2 XML Names and Java Class, Method, and Constant Names
XML Name Class Name Method Name Constant Name
mixedCaseName MixedCaseName getMixedCaseName MIXED_CASE_NAME
Answer42 Answer42 getAnswer42 ANSWER_42
name-with-dashes NameWithDashes getNameWithDashes NAME_WITH_DASHES
other_punct-chars OtherPunctChars getOtherPunctChars OTHER_PUNCT_CHARS
C.2.1 Collisions and conflicts
It is possible that the name-mapping algorithm will map two distinct
XML names to the same word list. This will result in a collision if,
and only if, the same Java identifier is constructed from the word
list and is used to name two distinct generated classes or two
distinct methods or constants in the same generated class. Collisions
are not permitted by the binding compiler and are reported as errors;
they may be repaired by revising XML name within the source schema or
by specifying a customized binding that maps one ot the two XML names
to an alternative Java identifer.
Method names are forbidden to conflict with Java keywords or literals,
with methods declared in java.lang.Object, or with methods declared in
the binding-framework classes. Such conflicts are reported as errors
and may be repaired by revising the appropriate schema.
</quote>
--
Hopefully helpfully yours,
Steve
--
Steven Tolkin steve.tolkin@fmr.com 617-563-0516
Fidelity Investments 82 Devonshire St. V8D Boston MA 02109
There is nothing so practical as a good theory. Comments are by me,
not Fidelity Investments, its subsidiaries or affiliates.
------------------------------
Date: 5 Dec 2002 11:45:13 -0800
From: michael.cambray@wellpoint.com (Mike Cambray)
Subject: What's the correct way to initialize an array to null?
Message-Id: <30d612e5.0212051145.4a2c5466@posting.google.com>
I reuse an array in a script and I'm not sure of the correct way to intialize it
to null after its been processed.
@array();
@array = "";
@array = ();
Are any of above valid?
------------------------------
Date: Thu, 05 Dec 2002 20:14:54 +0000
From: John Imrie <john@imrie37.fsnet.co.uk>
Subject: Re: What's the correct way to initialize an array to null?
Message-Id: <3DEFB3BE.3000001@imrie37.fsnet.co.uk>
Mike Cambray wrote:
> I reuse an array in a script and I'm not sure of the correct way to intialize it
> to null after its been processed.
> @array();
> @array = "";
> @array = ();
> Are any of above valid?
>
use @array = ();
This will keep the array defined but empty
@array = "" assigns "" to $array[0] :-)
------------------------------
Date: 5 Dec 2002 20:28:11 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: What's the correct way to initialize an array to null?
Message-Id: <asocsr$2ir$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Mike Cambray:
> I reuse an array in a script and I'm not sure of the correct way to
> intialize it to null after its been processed.
> @array();
> @array = "";
> @array = ();
> Are any of above valid?
Save for the first, all are valid only that they do different things.
The third sets the first array element to the empty string. It's a false
value but it is defined.
However, good programs hardly ever need to explicitely empty a variable.
The keyword here is scoping. If you restrict your variables to the
minimal scope (range, if you will) they will get freed automatically. If
you need another variable somewhere else create a new lexical variable.
Lexical variables are declared using my(). Below is a good example:
while (<FILE>) {
my @fields; # always a fresh array
for my $e (@another_array) {
push @fields, $e if some_condition($_, $e);
}
...
}
print "@fields"; # compile-time error: @fields only visible within
# while-block
Each iteration over <FILE> has its own @fields array. No need to clear
anything.
The bad version:
while (<FILE>) {
@fields = (); # we need to do that
# otherwise @fields grows and grows
for my $e (@another_array) {
push @fields, $e if some_condition($_, $e);
}
...
}
print "@fields"; # variable is still there!
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, 05 Dec 2002 20:36:24 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: What's the correct way to initialize an array to null?
Message-Id: <3DEFB85E.4080809@dev.null>
Mike Cambray wrote:
> I reuse an array in a script and I'm not sure of the correct way to intialize it
> to null after its been processed.
> @array();
> @array = "";
> @array = ();
> Are any of above valid?
>
@array() is a syntax error. @array="" Gives you an array with one
element, which happens to be "". @array =() will assign the empty list
to @array. You can also say
undef @array;
which will undefine the variable. It's not clear to me what, if
anything, the difference between undef @array and @array=() is. perldoc
-f undef leaves the notion of undefinedness, well, undefined. I thought
undef makes the variable just disappear, so I tried this:
use warnings;
my @array=(1,2,3);
undef @array;
my @array=(34,56);
expecting to get away with declaring @array twice, but I got a warning
about masking the earlier declaration of @array in line 4.
------------------------------
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 4222
***************************************