[19446] in Perl-Users-Digest
Perl-Users Digest, Issue: 1641 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 28 18:05:35 2001
Date: Tue, 28 Aug 2001 15:05:12 -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: <999036312-v10-i1641@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 28 Aug 2001 Volume: 10 Number: 1641
Today's topics:
Re: Java mucks up split <cberry@cinenet.net>
a perl module dedicated to lists ? <Francis.Derive@wanadoo.fr>
Re: a perl module dedicated to lists ? <Tassilo.Parseval@post.rwth-aachen.de>
Re: a perl module dedicated to lists ? (Logan Shaw)
Re: a perl module dedicated to lists ? <Tassilo.Parseval@post.rwth-aachen.de>
Re: Adding a html break tag at eol in text... <matt@matthewlaw.comNOSPAM>
Any code snippet for http-post with enctype "applicatio (Willy Kreim)
Re: Beginner PERL Book (Abigail)
Re: Beginner PERL Book <parisbookstore@qwest.net>
Re: Calling a Java Class from within PERL <ilya@martynov.org>
Re: CODE reference to member function of package Confus <iltzu@sci.invalid>
Re: CODE reference to member function of package Confus (Randal L. Schwartz)
Re: DBI connect string for Sybase Anywhere Studio (Upda <kkoch@kxsu.de>
Re: FAQ asking (was Re: CODE reference to member functi (Tad McClellan)
Re: FAQ asking (was Re: CODE reference to member functi <uri@sysarch.com>
Re: Help with Piped command, capturing output (Jonathan Cunningham)
Re: Help! Trying to configure SendMail.pm is driving m <samneric@tigerriverOMIT-THIS.com>
Re: how to do 'c' - 'a' = 2 in perl? <cberry@cinenet.net>
Re: how to get character from string one by one? (Abigail)
Re: how to get character from string one by one? <krahnj@acm.org>
Re: how to get character from string one by one? (Logan Shaw)
Re: how to get named constants in Perl (Abigail)
Re: It's to AM for me to think (Abigail)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 28 Aug 2001 20:39:28 -0000
From: Craig Berry <cberry@cinenet.net>
Subject: Re: Java mucks up split
Message-Id: <Xns910B8AEF6C06Bcberrycinenetnet1@207.126.101.92>
194.203.212.8 [demerphq@hotmail.com] wrote in news:XjNi7.1385$3x.4984
@news.bc.tac.net:
> Why do you want Sun to get it right? Aren't you a perler?
Many of us code in more than one language. I happen to do the bulk of my
work in Java, with most of the rest being in Perl. On an esthetic level, I
prefer Perl, but Java is required for the apps I'm paid to create.
The more the two languages share semantics in borrowed features like
regexes, the happier I'll be.
--
Craig Berry <http://www.cinenet.net/~cberry/>
"That which is now known, was once only imagined." - William Blake
------------------------------
Date: 28 Aug 2001 21:28:53 +0200
From: "Francis Derive" <Francis.Derive@wanadoo.fr>
Subject: a perl module dedicated to lists ?
Message-Id: <B7B1BE31-354F9@193.248.252.253>
Hello !
This is it : is there a perl module dedicated to lists ?
i.e., (member $elem @list), oh ! I beg your pardon : member( $elem, @list);
delete( $elem, @list ); ( in many ways ). And so on, closed to so long as
Lisp does.
Merci.
Francis
------------------------------
Date: Tue, 28 Aug 2001 21:52:30 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: a perl module dedicated to lists ?
Message-Id: <3B8BF67E.9080605@post.rwth-aachen.de>
Francis Derive wrote:
> Hello !
>
> This is it : is there a perl module dedicated to lists ?
I think you wouldn't need one. The functions that Perl has will do most
of that for you. member can quickly be done in a for loop whereas delete
can either be done with delete() [1] or splice.
[1] delete however leaves your array with a 'hole' if you delete
somewhere in the middle.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: 28 Aug 2001 16:19:55 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: a perl module dedicated to lists ?
Message-Id: <9mh1tr$fjn$1@charity.cs.utexas.edu>
In article <B7B1BE31-354F9@193.248.252.253>,
Francis Derive <Francis.Derive@wanadoo.fr> wrote:
>This is it : is there a perl module dedicated to lists ?
>
>i.e., (member $elem @list), oh ! I beg your pardon : member( $elem, @list);
>delete( $elem, @list );
Those don't exist directly, but instead of member, you can do this:
grep ($elem eq $_, @list) > 0
and instead of delete you can do this:
grep ($elem ne $_, @list)
On the first one, you can leave off "> 0" if it occurs in a scalar
context. The second one returns a new value rather than modifying the
list.
If you are worrying about sets of strings (a common case in Perl),
you can turn your list into a hash:
%hash = map { $_ => 1 } @list;
And then you can test for membership:
if (exists $hash{$elem}) { whatever... }
and you can delete:
delete $hash{$elem};
You can convert back into a list easily enough:
@list = keys %hash; # or "sort keys %hash" if you want
If you're doing lots of set operations, this is likely an efficient way
to do it, since hashes really do internally use a hash and therefore
these operations are O(1) execution time. (At least most of the time.
I'm not sure delete is always O(1), but it probably is.)
If you're dealing with sets of something other than strings, life is a
little more difficult. But then, Perl is a sort of a text-centric
language.
Also, go to http://search.cpan.org/ and search for List::Util. That
module has a few list utility functions (and ideas on how to implement
others).
- Logan
--
"Our grandkids love that we get Roadrunner and digital cable."
(Advertisement for Time Warner cable TV and internet access, July 2001)
------------------------------
Date: Tue, 28 Aug 2001 23:39:44 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: a perl module dedicated to lists ?
Message-Id: <3B8C0FA0.2050402@post.rwth-aachen.de>
Logan Shaw wrote:
> In article <B7B1BE31-354F9@193.248.252.253>,
> Francis Derive <Francis.Derive@wanadoo.fr> wrote:
>
>>This is it : is there a perl module dedicated to lists ?
>>
>>i.e., (member $elem @list), oh ! I beg your pardon : member( $elem, @list);
>>delete( $elem, @list );
>>
>
> Those don't exist directly, but instead of member, you can do this:
>
> grep ($elem eq $_, @list) > 0
Yet one should mark that grep can be slightly less efficient that loop
last()ed on finding an element.
> and instead of delete you can do this:
>
> grep ($elem ne $_, @list)
Well, rather @new = grep(...), otherwise it'd be a no-op.
> On the first one, you can leave off "> 0" if it occurs in a scalar
> context. The second one returns a new value rather than modifying the
> list.
Ah, ok, you mentioned yourself.
> If you are worrying about sets of strings (a common case in Perl),
> you can turn your list into a hash:
>
> %hash = map { $_ => 1 } @list;
>
> And then you can test for membership:
>
> if (exists $hash{$elem}) { whatever... }
In this case (since you initialize each hash-element with 1) you could
even write "if ($hash{$elem})" which I find a little more eye-friendly.
But here this does rather the same.
> and you can delete:
>
> delete $hash{$elem};
>
> You can convert back into a list easily enough:
>
> @list = keys %hash; # or "sort keys %hash" if you want
Though, one might want to add, doing it with hashes has side-effects.
You automatically delete dupilcate entries. Sure, these can be pleasant
side-effects in some cases.
> If you're doing lots of set operations, this is likely an efficient way
> to do it, since hashes really do internally use a hash and therefore
> these operations are O(1) execution time. (At least most of the time.
> I'm not sure delete is always O(1), but it probably is.)
Ah no. Turning an array into a hash is at least O(n)...turning it back
another O(n) plus the additional sort with O(n log(n)) if that is done
as well.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Tue, 28 Aug 2001 22:13:48 +0000
From: Matt L <matt@matthewlaw.comNOSPAM>
Subject: Re: Adding a html break tag at eol in text...
Message-Id: <9mh1c3$70j$1@plutonium.btinternet.com>
Thankyou. I'll give it a try.
John Callender wrote:
> "Matt L." wrote:
>
>> I need a snippet of
>> code (or some guidance 80) that reads in the text from the aforementioned
>> textarea and inserts a html <br> tag wherever the end of line character
>> is encountered.
>
> [snip]
>
>> Does it make any difference that the CGI runs on Linux and the textarea
>> is edited on a Win32 based system?
>
> Yes, it does, since the two systems have different ideas about
> what an "end of line" sequence consists of.
>
> If I were sure that the code would never have to handle any but
> Win32-based input, I might try something like this:
>
> $text =~ s{\r\n}{<BR>\n}g;
>
> Otherwise, I'd probably split it into two steps, like this:
>
> $text =~ s{\r\n?}{\n}g;
> $text =~ s{\n}{<BR>\n}g;
>
------------------------------
Date: 28 Aug 2001 13:03:38 -0700
From: willykk@my-deja.com (Willy Kreim)
Subject: Any code snippet for http-post with enctype "application/x-www-form-urlencoded"
Message-Id: <20a02d3.0108281203.a5a42fd@posting.google.com>
Is there any code snippet out there showing how to retrieve a results
page from a web server after sending two vars via method="POST"
enctype="application/x-www-form-urlencoded"?.
I'm a beginner with perl and would prefer to use tested, ready-made
code snippets.
Oh, did I mention that I'd need to fake the the referrer on the http
header, a la curl?.
Thanks in advance for any info you can provide.
Willy.
------------------------------
Date: 28 Aug 2001 20:38:51 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Beginner PERL Book
Message-Id: <slrn9oo0av.rpa.abigail@alexandra.xs4all.nl>
at (mataloev1.net) wrote on MMCMXIX September MCMXCIII in
<URL:news:3b8bad5d_1@newsa.ev1.net>:
:)
:) Can someone tell me which is the "best" beginner PERL book out there? I have
:) taken a 2 day course for PERL where they shoved quite a bit of info and am
:) having a hard time remembering anything at all...I want to start from the
:) basics. I bought two books. PERL Annotated Archives and PERL from the ground
:) up.
You got a two day course, and you still cannot spell Perl correctly?
Shame on you.
As for the "best" beginners book, there isn't one. There are some good
books, and many bad ones. What's a good book for one isn't a good book
for someone else. But that's common sense.
Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
print } sub __PACKAGE__ { &
print ( __PACKAGE__)} &
__PACKAGE__
( )
------------------------------
Date: Tue, 28 Aug 2001 15:39:19 -0600
From: "Paris Bookstore" <parisbookstore@qwest.net>
Subject: Re: Beginner PERL Book
Message-Id: <yaUi7.24$EC5.31523@news.uswest.net>
I started out with Elizabeth Castro's "Perl and CGI for the Worldwide Web -
Visual Quickstart Guide" and it did me great for getting up and running
quickly.
Now that I'm looking into some more complicated stuff, the "Perl CD
Bookshelf" published by O'Reilly has been an excellent resource.
Brad
--
Paris on the Platte Bookstore
1553 Platte St.
Denver, CO 80202
303-455-2451
www.parisontheplatte.com
<Jason B. Swaim matalo (at) ev1.net> wrote in message
news:3b8bad5d_1@newsa.ev1.net...
>
> Can someone tell me which is the "best" beginner PERL book out there? I
have
> taken a 2 day course for PERL where they shoved quite a bit of info and am
> having a hard time remembering anything at all...I want to start from the
> basics. I bought two books. PERL Annotated Archives and PERL from the
ground
> up.
>
> Or should I just go to a university and take the time to learn?
> Thank you,
> Jason B. Swaim
------------------------------
Date: 28 Aug 2001 23:04:06 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Calling a Java Class from within PERL
Message-Id: <878zg4dn15.fsf@abra.ru>
>>>>> On 28 Aug 2001 10:39:25 -0700, rxsid@aol.com (Team ALN) said:
TA> Hello all,
TA> Does anyone know how to call a Java Class from within PERL? I have
TA> tried using the system function to no avail. I would prefer not to
TA> use the exec() if at all possible. Any ideas?
Try modules Java or Inline::Java (available from CPAN)
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| 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: 28 Aug 2001 18:51:29 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: CODE reference to member function of package Confusing..
Message-Id: <999021504.1215@itz.pp.sci.fi>
In article <74f348f7.0108271201.33230c02@posting.google.com>, Yves Orton wrote:
>
>Yves
>PS I bet there is not a soul on CLPM that has not at one time or
>another asked a question from the FAQ. Including you.
*raises hand*
Whatever other mistakes I may have made, I don't think I've ever asked a
question that was in Perl FAQ. I've answered some without remembering
that they were in the FAQ, but I've never asked any. Google agrees.
Sorry. I just wanted to disprove your categorical statement.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post something,
we discuss its implications. If the discussion happens to answer a question
you've asked, that's incidental." -- nobull in comp.lang.perl.misc
------------------------------
Date: 28 Aug 2001 12:34:04 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: CODE reference to member function of package Confusing..
Message-Id: <m1k7zo0yj7.fsf@halfdome.holdit.com>
>>>>> "Ilmari" == Ilmari Karonen <iltzu@sci.invalid> writes:
Ilmari> In article <74f348f7.0108271201.33230c02@posting.google.com>, Yves Orton wrote:
>>
>> Yves
>> PS I bet there is not a soul on CLPM that has not at one time or
>> another asked a question from the FAQ. Including you.
Ilmari> *raises hand*
Ilmari> Whatever other mistakes I may have made, I don't think I've ever asked a
Ilmari> question that was in Perl FAQ. I've answered some without remembering
Ilmari> that they were in the FAQ, but I've never asked any. Google agrees.
Ilmari> Sorry. I just wanted to disprove your categorical statement.
Seconded. How will Yves pay up on this lost bet? :)
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: Tue, 28 Aug 2001 21:09:51 +0200
From: Klaus Koch <kkoch@kxsu.de>
Subject: Re: DBI connect string for Sybase Anywhere Studio (Update)
Message-Id: <9mgq15$1ufg6$1@ID-101758.news.dfncis.de>
Klaus Koch wrote:
> I want to connect to a Sybase Anywhere Studio database with the DBD::ODBC
> module. The database server is called "limes" and the database is called
> "customers".
> I dont know what to use in the connect string to get access to the
> database.
> I tried:
> $dbh = DBI->connect("dbi:ODBC:'uid=<user>;pwd=<pwd>;eng=limes'");
> but I get a connection error.
it doesnt matter what i try, i keep getting this error:
DBI->connect('uid=<user>;pwd=<pwd>;eng=limes') failed: [iODBC][Driver
Manager]Invalid string or buffer length (SQL-S1090)
[iODBC][Driver Manager]Data source name not found and no default driver
specified. Driver could not be loaded (SQL-IM002)(DBD: db_login/SQLConnect
err=-1) at line 6
the iODBC driver is definately installed in /usr/local/lib and I dont get
errors from "use DBD::ODBC" and "use DBI" in the perl programm.
It wasnt me who installed the DBD module and the iODBC driver, so I am not
very familiar with it and I couldnt find anything about this error on the
net.
I am really becoming desperate about this problem.
I would be very happy about any help.
Klaus
------------------------------
Date: Tue, 28 Aug 2001 13:37:52 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: FAQ asking (was Re: CODE reference to member function of package Confusing..)
Message-Id: <slrn9onlng.sj0.tadmc@tadmc26.august.net>
194.203.212.8 [demerphq@hotmail.com] <194.203.212.8[demerphq@hotmail.com]> wrote:
>In the future when the urge to write a mail like that comes on I will write it to myself first.
Just "count to ten" first:
http://mail.augustmail.com/~tadmc/clpmisc.shtml
It would appear that even experienced Usenauts can find
helpful ideas there :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 28 Aug 2001 19:10:40 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: FAQ asking (was Re: CODE reference to member function of package Confusing..)
Message-Id: <x77kvohufb.fsf@home.sysarch.com>
>>>>> "TM" == Tad McClellan <tadmc@augustmail.com> writes:
TM> http://mail.augustmail.com/~tadmc/clpmisc.shtml
so when will that link be autoposted here?
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: 28 Aug 2001 12:59:45 -0700
From: dawfun@seanet.com (Jonathan Cunningham)
Subject: Re: Help with Piped command, capturing output
Message-Id: <4d6fd5fc.0108281159.1bf3b7f0@posting.google.com>
Michael Budash <mbudash@sonic.net> wrote in message news:<mbudash-008F99.21503120082001@news.sonic.net>...
>
> hmmm... you might try appending " 2>&1" to $pgpcmd and see what you
> get... also: it may not be able to find your config file: as i recall, i
> had to put it (pgp.cfg) in the same dir as the script with this is in it:
>
> PubRing="/full/path/to/pubring.pkr"
> Verbose=2
>
> this was with pgp 5.x for irix 6.x, so YMMV...
>
> hth-
No luck here either. Lame.
JC
------------------------------
Date: Tue, 28 Aug 2001 17:34:17 -0400
From: Samneric <samneric@tigerriverOMIT-THIS.com>
Subject: Re: Help! Trying to configure SendMail.pm is driving me crazy!!
Message-Id: <MPG.15f5d869da5f3c8f9896a0@news.onemain.com>
JerryGarciuh wrote:
> My tests got error :
> no host: , please specify SMTP server with "$obj = new
> SendMail('your.smtp.server');"
Yes, NOT: "no host: please edit $smtpserver example in SendMail.pm"
> So in SendMail.pm I edited
> $smtpserver = "mail.server.com";
Actually, you edited "# $smtp = 'mail.server.com';" - in a commented line.
SendMail.pm contains commented example code, so you are probably not having any
effect editing those portions. But STOP "configuring" before you change
something that isn't going to be so harmless. If you un-commented any lines in
the file, you had better re-comment them. There is no configuring required.
From author's example script:
---------
use SendMail;
# Create the object without any arguments,
# i.e. localhost is the default SMTP server.
$sm = new SendMail();
---------
You don't want to do that. As it says above, if you don't pass a server name
then it defaults to 'localhost'.
You want to pass your SMTP server name here instead:
$sm = new SendMail('smtp.jgarciuh.com');
------------------------------
Date: Tue, 28 Aug 2001 20:43:17 -0000
From: Craig Berry <cberry@cinenet.net>
Subject: Re: how to do 'c' - 'a' = 2 in perl?
Message-Id: <Xns910B8B94E9FD4cberrycinenetnet1@207.126.101.92>
tadmc@augustmail.com (Tad McClellan) wrote in
news:slrn9onck7.sc0.tadmc@tadmc26.august.net:
> cheng huang <cheng@cs.wustl.edu> wrote:
>>Say I have a $letter variable and want to know what it is exactly, can
>>sb.
>
> What is "sb"?
I first read it as 'antimony', but that's just me. :) I think it's a
pointless hyperabbreviation of 'somebody'.
--
Craig Berry <http://www.cinenet.net/~cberry/>
"That which is now known, was once only imagined." - William Blake
------------------------------
Date: 28 Aug 2001 19:31:27 GMT
From: abigail@foad.org (Abigail)
Subject: Re: how to get character from string one by one?
Message-Id: <slrn9onscj.rpa.abigail@alexandra.xs4all.nl>
Craig Berry (cberry@cinenet.net) wrote on MMCMXIX September MCMXCIII in
<URL:news:Xns910B65D8AFCC1cberrycinenetnet1@207.126.101.92>:
^^ demerphq@hotmail.com (Yves Orton) wrote in
^^ news:74f348f7.0108280139.332a852a@posting.google.com:
^^ > I will be posting an overview of a bunch of benchmarks that I have
^^ > done in this area to the thread 'one character at a time'. There are
^^ > a variety of methods (5 basic ideas) to achieve it ranging from fast
^^ > to slow. Split doesnt perform that well actually.
^^
^^ Let's see...substr, split, unpack, m/(.)/sg, and...what?
chop.
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: Tue, 28 Aug 2001 20:20:48 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: how to get character from string one by one?
Message-Id: <3B8BFD8D.D7F15BBE@acm.org>
Craig Berry wrote:
>
> demerphq@hotmail.com (Yves Orton) wrote in
> news:74f348f7.0108280139.332a852a@posting.google.com:
> > I will be posting an overview of a bunch of benchmarks that I have
> > done in this area to the thread 'one character at a time'. There are
> > a variety of methods (5 basic ideas) to achieve it ranging from fast
> > to slow. Split doesnt perform that well actually.
>
> Let's see...substr, split, unpack, m/(.)/sg, and...what?
vec()
John
--
use Perl;
program
fulfillment
------------------------------
Date: 28 Aug 2001 16:00:36 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: how to get character from string one by one?
Message-Id: <9mh0pk$fdu$1@charity.cs.utexas.edu>
In article <Xns910B65D8AFCC1cberrycinenetnet1@207.126.101.92>,
Craig Berry <cberry@cinenet.net> wrote:
>demerphq@hotmail.com (Yves Orton) wrote in
>news:74f348f7.0108280139.332a852a@posting.google.com:
>> I will be posting an overview of a bunch of benchmarks that I have
>> done in this area to the thread 'one character at a time'. There are
>> a variety of methods (5 basic ideas) to achieve it ranging from fast
>> to slow. Split doesnt perform that well actually.
>
>Let's see...substr, split, unpack, m/(.)/sg, and...what?
Also:
$s = "abc123";
while ($s =~ s/(.)//s)
{
push (@s, $1);
}
Can't imagine that'd be terribly fast. Maybe this has a decent shot at
being fast:
$s =~ s/(.)/"\Q$1\E", /sg;
@s = eval "($s)";
OK, now I have to admit it's convenient to be able to throw in extra
commas at the end of lists.
- Logan
--
"Our grandkids love that we get Roadrunner and digital cable."
(Advertisement for Time Warner cable TV and internet access, July 2001)
------------------------------
Date: 28 Aug 2001 19:00:15 GMT
From: abigail@foad.org (Abigail)
Subject: Re: how to get named constants in Perl
Message-Id: <slrn9onqi3.rpa.abigail@alexandra.xs4all.nl>
Peter J. Acklam (jacklam@math.uio.no) wrote on MMCMXIX September MCMXCIII
in <URL:news:cxcsnech1oo.fsf@tiamat.uio.no>:
)) merlyn@stonehenge.com (Randal L. Schwartz) wrote:
))
)) > >>>>> "Martien" == Martien Verbruggen <mgjv@tradingpost.com.au> writes:
)) >
)) > Martien> use const PI => 4 * atan2(1, 1);
)) >
)) > Why the 4? Why not just pick the right x,y?
))
)) Because that's what's suggested in the docs. The "constant" man
)) page says
))
)) use constant PI => 4 * atan2 1, 1;
))
)) and the "perlsub" man page says
))
)) sub PI () { 4 * atan2 1, 1 } # As good as it gets,
))
)) > use constant PI => atan2(0,-1);
))
)) Sure, but this isn't suggested anywhere in the docs.
Just because it's in the docs doesn't mean you shouldn't think for
yourself. The docs aren't about pi. They are about how to use the
pragma.
Abigail
--
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$==-2449231+gm_julian_day+time);do{until($=<$#r){$_.=$r[$#r];$=-=$#r}for(;
!$r[--$#r];){}}while$=;$,="\x20";print+$_=>September=>MCMXCIII=>=>=>=>=>=>=>=>'
------------------------------
Date: 28 Aug 2001 19:06:11 GMT
From: abigail@foad.org (Abigail)
Subject: Re: It's to AM for me to think
Message-Id: <slrn9onqt7.rpa.abigail@alexandra.xs4all.nl>
Ilmari Karonen (iltzu@sci.invalid) wrote on MMCMXIX September MCMXCIII in
<URL:news:999018371.28999@itz.pp.sci.fi>:
@@ In article <slrn9ome4q.r1r.abigail@alexandra.xs4all.nl>, Abigail wrote:
@@ >Ilmari Karonen (iltzu@sci.invalid) wrote on MMCMXIX September MCMXCIII in
@@ ><URL:news:998962555.11327@itz.pp.sci.fi>:
@@ >-- In article <9me1e0$c5n$1@mamenchi.zrz.TU-Berlin.DE>, Anno Siegel wrote:
@@ >-- >
@@ >-- >That could only happen if the overhead of "shift @array" vs. "$array[ 0]"
@@ >-- >is greater than one round through the loop. I was betting that it isn't
@@ >-- >(and still do), but you're right to point it out.
@@ >--
@@ >-- Besides, it could well be that shift() is actually faster than fetching
@@ >-- an array element by index. No, I'm not going to benchmark it right now.
@@ >
@@ >It could. The point is that we don't know, so the claim that the
@@ >optimization "comes for free" is unfounded.
@@
@@ Well, I we do know that shift() and array indexing are both O(1), since
@@ that much is documented. This is achieved by implementing Perl arrays
@@ as contiguous chunks of memory, with an adjustable beginning pointer.
@@
@@ If we assume, given the above, a halfway sane implementation of both
@@ operarations, that implies they take approximately the same time, since
@@ the fundamental actions they must perform are nearly identical. That
@@ makes any optimization enabled by switching between them "free" for all
@@ but the most unreasonably pedantic definitions.
Ah, I see. Updating a pointer is "free" compared to making on more
comparison (which is what you are saving in the loop).
Point is that the savings are utterly small. Compared to *that*, the
difference between an array lookup and a shift aren't "free".
Feel free to call the investment "free", but then be fair and don't
talk about any savings.
Abigail
--
perl -Mstrict='}); print "Just another Perl Hacker"; ({' -le1
# Ryokan laughing
# beside a stream. Two songbirds
# nest in a peach tree.
------------------------------
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 1641
***************************************