[19245] in Perl-Users-Digest
Perl-Users Digest, Issue: 1440 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 4 06:05:36 2001
Date: Sat, 4 Aug 2001 03:05:10 -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: <996919510-v10-i1440@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 4 Aug 2001 Volume: 10 Number: 1440
Today's topics:
Re: \nhelp <walnut@froggy.com.au>
ActiveState Perl <-> Cygwin perl and newlines... (nobody)
Re: Appanding to hash_key_value <walnut@froggy.com.au>
Baiting Gozilla to obtain quality code for nothing!! <walnut@froggy.com.au>
Benchmarking Perl modules <Dave.Stafford@globis.net>
Re: Benchmarking Perl modules <gnarinn@hotmail.com>
Can I make methods private/public? <perlgirl@cfl.rr.com>
Re: Can I make methods private/public? <ilya@martynov.org>
Re: CGI -> Apache Problem <walnut@froggy.com.au>
Re: cgi cookie question <dbe@wgn.net>
CGI script (Joe Chung)
Re: CGI script (David Efflandt)
Re: COmments appreciated <markku@huilustudio.fi>
comp.infosystems.www.authoring.cgi now moderated <godzilla@stomp.stomp.tokyo>
Re: comp.infosystems.www.authoring.cgi now moderated (Randal L. Schwartz)
Re: comp.infosystems.www.authoring.cgi now moderated <cyberjeff@sprintmail.com>
Re: comp.infosystems.www.authoring.cgi now moderated <godzilla@stomp.stomp.tokyo>
Re: Database Problem <walnut@froggy.com.au>
Re: Extract the relative sorting of items from multiple (David Combs)
FAQ: How do I manipulate arrays of bits? <faq@denver.pm.org>
Re: frustrated beginner's question (Anthony_Barker)
how can I permanently change @INC? <perlgirl@cfl.rr.com>
Re: how can I permanently change @INC? blah@blah.blah.invalid
Re: How do I make sure I get all form fields and values <walnut@froggy.com.au>
Re: How do I select a random element from an array? <gm@magpage.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 04 Aug 2001 18:53:40 +1000
From: Walnut <walnut@froggy.com.au>
Subject: Re: \nhelp
Message-Id: <osmlmtsu04o8jf2utbc21odbsmhh9b2tmm@4ax.com>
On Thu, 26 Jul 2001 21:38:14 GMT, jtjohnston
<jtjohnston@courrier.usherb.ca> wrote:
> Hi,
> I have a text file I use as a database. I have many instances of lines
> starting with "&&4;" Can someone show me how to re-attach the "&&4;" to
> the previous line?
>
> See following example:
>
> ---snip---
> Record1field2field3field4field5field6field7
> Record2field2field3
> &&4; field4field5field6field7
> Record3field2field3field4field5field6field7
> ---snip---
Suck file into a variable and substitute as follows:
$variable ~= s!\n&&.;!\n!g;
------------------------------
Date: Sat, 04 Aug 2001 08:22:06 GMT
From: nobody@nobody.com (nobody)
Subject: ActiveState Perl <-> Cygwin perl and newlines...
Message-Id: <OgOa7.263742$E4.6547889@amsnews02.chello.com>
I'm sure this is a common question, and I tried to find answers
in the newsgroups, but I just can't find a simple solution.
Using ActiveState Perl, newlines are handled in the msdos way,
and doing a:
print "hello\nHow are you?\n";
will print correct newlines.
Running the same line of code in cygwin perl, it won't print
the newlines, because cygwin only outputs a \n.
Is there a simple setting that makes cygwin behave like
activeperl, without doing many changes in the code?
------------------------------
Date: Sat, 04 Aug 2001 18:53:36 +1000
From: Walnut <walnut@froggy.com.au>
Subject: Re: Appanding to hash_key_value
Message-Id: <3ahlmtkoojmai3j4ljvcesjb0ikbjbitso@4ax.com>
On 20 Jul 2001 15:53:13 -0700, npatel@webley.com (Nipa) wrote:
> How do i append to an existing key's value in a
> Hash
> this is that the code looks like:
> if($formdata{$key})
> {
> $formdata{$key} .= "$value";
> }
> else { $fromdata{$key} = $value; }
If you are just trying to get entries from a multi select text box, go
get the old Perl 4 version of the cgi.pm library (called cgilib.pl I
think or cgi_lib.pl) and check out how it is done. I only recommend
the old version as it is small and simple for a beginner.
------------------------------
Date: Sat, 04 Aug 2001 18:53:42 +1000
From: Walnut <walnut@froggy.com.au>
Subject: Baiting Gozilla to obtain quality code for nothing!!
Message-Id: <3lqlmt4kpdkevf6uaihh6flbhb6ph4of82@4ax.com>
If you are working on a project and either you, your work mates or the
boss produce absolutely crap code here is what to do to keep that
budget under control, meet your deadline and get that pay rise:
1. Find a few particularly bad pieces of code that needs fixing by an
expensive professional then realize that behold, in our midst roams
such a one.
2. Post the trashy code here from a few different email accounts,
pretending you are a beginner who knows nothing and flaunting every
perl rule of syntax and style.
3. Deliberately make such huge errors that, lo and behold, Gozilla!
will feel a deep urge and burning obligation to spend oodles of time
going through his/her personal library and O'Reilly books to provide
the exact code you require - at the drop of a hat.
4. Invest in a bit of controversy. In the process of trying to prove
that he/she is the best of them all, you will get for your little
effort a line-by-line, logical, fully commented, significant snippet
of code ready to cut and paste into your favorite client's web
service.
4. Laugh all the way to the bank. If you can force yourself to take
the initial, "Your code sucks rotten eggs you useless piece of
elephant dung!", post in the chin guess what?
Normally it would cost ++$75/hour for a piece of code to this quality
but thanks to Gozilla!'s egotistical compulsion ... ALL FOR ABSOLUTE
NOTHING - ZERO - ZILCH - NADA!
What a great service! Keep up the good work! <<--- ego builder here!
;)
------------------------------
Date: Fri, 03 Aug 2001 17:48:48 GMT
From: "Dave Stafford" <Dave.Stafford@globis.net>
Subject: Benchmarking Perl modules
Message-Id: <4uBa7.327717$XL1.5660264@nlnews00.chello.com>
There was a thread recently about performance differences when loading
libraries such as DBI, CGI etc. I decided to do a little testing myself to
see if there was really such a difference to the web server overall.
The test setup was:
Celeron @ 700Mhz, 256 MB RAM
Windows 98 running Apache 1.3.19 with mod_perl and mod_ssl
Netscape 6
IE 5.5
The test worked as follows:
1. A web page downloaded a java applet which goes into a loop of 100
executions.
2. Each execution connects to the web server (on the same machine) and
executes the test script.
3. The test script loads the libraries, returns a single value (system time)
and closes.
4. The applet prints the value.
First I tested without mod_perl, i.e. every request caused Perl to be run,
the script to be compiled, and executed.
no libs ->15 Executions/second
DBI.pm -> 4 Executions/second
CGI.pm -> 5 Executions/second
cgi-lib.pl -> 13 Executions/second
all abover -> 3 Executions/second
With mod_Perl there was no difference whether one or all libraries are
loaded (not suprising), but the big difference was I could achieve a peak of
64 excutions/second.
I then tried mod_perl and IE5.5, and it could only manage *9*
executions/sec. Each execution however seems to be generating intense disk
activity that is slowing down the test. I cannot seem stop this disk
activity by playing with cache settings etc.
Anyhow, the results show that if you want to achieve high (serial)
throughput use mod_perl. No brainer perhaps, but it's nice to see the
numbers.
Perhaps I'll compare platforms some time.
Dave
------------------------------
Date: Sat, 4 Aug 2001 09:11:14 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Benchmarking Perl modules
Message-Id: <996916274.0833499156869948.gnarinn@hotmail.com>
In article <4uBa7.327717$XL1.5660264@nlnews00.chello.com>,
Dave Stafford <Dave.Stafford@globis.net> wrote:
>There was a thread recently about performance differences when loading
>libraries such as DBI, CGI etc. I decided to do a little testing myself to
>see if there was really such a difference to the web server overall.
>
>The test setup was:
>
>Celeron @ 700Mhz, 256 MB RAM
>Windows 98 running Apache 1.3.19 with mod_perl and mod_ssl
>Netscape 6
>IE 5.5
>
>The test worked as follows:
>1. A web page downloaded a java applet which goes into a loop of 100
>executions.
>2. Each execution connects to the web server (on the same machine) and
>executes the test script.
>3. The test script loads the libraries, returns a single value (system time)
>and closes.
>4. The applet prints the value.
>
>First I tested without mod_perl, i.e. every request caused Perl to be run,
>the script to be compiled, and executed.
>
>no libs ->15 Executions/second
>DBI.pm -> 4 Executions/second
>CGI.pm -> 5 Executions/second
>cgi-lib.pl -> 13 Executions/second
>all abover -> 3 Executions/second
>
>With mod_Perl there was no difference whether one or all libraries are
>loaded (not suprising), but the big difference was I could achieve a peak of
>64 excutions/second.
>
>I then tried mod_perl and IE5.5, and it could only manage *9*
>executions/sec. Each execution however seems to be generating intense disk
>activity that is slowing down the test. I cannot seem stop this disk
>activity by playing with cache settings etc.
>
It is also possible that netscape is also limiting your executions/second.
It might be interesting to run your test with a LWP::Simple script
instead of browsers.
>Anyhow, the results show that if you want to achieve high (serial)
>throughput use mod_perl. No brainer perhaps, but it's nice to see the
>numbers.
>
other 'heavy' modules also benefit greatly from mod_perl, such as
Date::Manip. web sites with mush dynamic content tend to use the same
modules in all or most scripts, so the efficiency is great.
in fact, if one page uses Date::Manip (or another monster module),
all pages might as well, as the module is loaded anyways.
>Perhaps I'll compare platforms some time.
and separate server and client(s) machines?
gnari
------------------------------
Date: Sat, 04 Aug 2001 04:47:47 GMT
From: tuxy <perlgirl@cfl.rr.com>
Subject: Can I make methods private/public?
Message-Id: <3B6B477C.6FDDC3EA@cfl.rr.com>
Is there a way to change the visibility of a sub (method) in a package
(class)?
Thank-You.
PG
------------------------------
Date: 04 Aug 2001 14:01:22 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Can I make methods private/public?
Message-Id: <87wv4kf8jx.fsf@abra.ru>
t> Is there a way to change the visibility of a sub (method) in a package
t> (class)?
Short answer: no
Long answer: if you really want it you can simulate private subs with
private package variables:
package SomePackage;
my $private = sub {
....
};
sub public {
....
$private->(@some_args);
....
}
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| 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: Sat, 04 Aug 2001 18:53:39 +1000
From: Walnut <walnut@froggy.com.au>
Subject: Re: CGI -> Apache Problem
Message-Id: <elmlmtcha5t88c1qlbunapgejdn2brnuji@4ax.com>
On Tue, 24 Jul 2001 11:01:38 +0200, "Georg Vassilopulos"
<Georg.Vassilopulos@SoftwareAG.de> wrote:
> my $command = "p:/tools/wni/unzip.exe $myFile";
> system ($command) or print "Fuck the system command:$!";
>
> Why does ist [not] work
Your system is probably not sensitive to abusive language unless it is
written in German. It probably does not understand English ;)
To fix it, replace the phrase "Fuck the system command" with something
like "Smack myself over the head with a heavy Perl book, then read it,
then go to www.google.com or perldoc to find my answers!" and it will
probably work again.
------------------------------
Date: Fri, 03 Aug 2001 18:36:07 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: cgi cookie question
Message-Id: <3B6B5187.6D4F4B47@wgn.net>
"Hmmm..." wrote:
>
> Hi.
>
> I am running test scripts to understand how cookies work with cgi. I am
> trying to create a cookie in one script, and retrieve it in another. Each
> script creates an html page to display the results. Here is the first script
> and it's output (which indicates that the cookie is created successfully:
>
> #!/usr/bin/perl -w
> ############## start of first script #############
> use CGI;
> $query = new CGI;
You need to set the cookie here when the header goes out before
the blank line after C-T header below.
> print <<top_html;
> content-type: text/html
>
> <HTML><HEAD><TITLE>
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles Mailto:dbe@todbe.com
/ ) /--< o // // http://dbecoll.webjump.com/ (Free site for Perl)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
------------------------------
Date: Sat, 04 Aug 2001 01:09:57 GMT
From: m_010@yahoo.com (Joe Chung)
Subject: CGI script
Message-Id: <3b6b4a6c.30370149@enews.newsguy.com>
i have the following CGI perl script from oreilly book:
I wonder why if I run the script from web browser like:
http://host/cgi-bin/test.pl
it will show the info of server.
But if i run it from unix prompt use perl
perl test.pl
It will not show any thing about server info.
I wonder Is it because the variable like $SERVER_NAME is only
avaliable in web sever process? so. I can't see it in perl test.pl
command? thanks.
==============================================================
#!/usr/local/bin/perl
print "Content-type: text/html", "\n\n";
print "<HTML>", "\n";
print "<HEAD><TITLE>About this Server</TITLE></HEAD>", "\n";
print "<BODY><H1>About this Server</H1>", "\n";
print "<HR><PRE>";
print "Server Name: ", $ENV{'SERVER_NAME'}, "<BR>", "\n";
print "Running on Port: ", $ENV{'SERVER_PORT'}, "<BR>", "\n";
print "Server Software: ", $ENV{'SERVER_SOFTWARE'}, "<BR>", "\n";
print "Server Protocol: ", $ENV{'SERVER_PROTOCOL'}, "<BR>", "\n";
print "CGI Revision: ", $ENV{'GATEWAY_INTERFACE'}, "<BR>", "\n";
print "<HR></PRE>", "\n";
print "</BODY></HTML>", "\n";
exit (0);
------------------------------
Date: Sat, 4 Aug 2001 03:33:23 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: CGI script
Message-Id: <slrn9mmr82.mr8.see-sig@typhoon.xnet.com>
On Sat, 04 Aug 2001 01:09:57 GMT, Joe Chung <m_010@yahoo.com> wrote:
> i have the following CGI perl script from oreilly book:
>
> I wonder why if I run the script from web browser like:
> http://host/cgi-bin/test.pl
>
> it will show the info of server.
>
> But if i run it from unix prompt use perl
> perl test.pl
> It will not show any thing about server info.
>
> I wonder Is it because the variable like $SERVER_NAME is only
> avaliable in web sever process? so. I can't see it in perl test.pl
> command? thanks.
It might be more enlightening to print all of the %ENV in both, instead of
a select few, to see what variables are available in each. Naturally,
webserver specific variables would only appear when run as CGI.
#!/usr/local/bin/perl -w
print "Content-type: text/plain\n\nENVIRONMENT\n\n";
foreach (sort keys %ENV) { print "$_: $ENV{$_}\n"; }
--
David Efflandt (Reply-To is valid) http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Sat, 04 Aug 2001 11:22:55 +0300
From: Markku Hirvonen <markku@huilustudio.fi>
Subject: Re: COmments appreciated
Message-Id: <d4cnmt8e5v7c6jlhha1ni50tiefo5u6ajg@4ax.com>
Thank you all very much. Your help has been most informative and i
have learned a lot.
Markku Hirvonen
------------------------------
Date: Fri, 03 Aug 2001 18:59:43 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: comp.infosystems.www.authoring.cgi now moderated
Message-Id: <3B6B570F.48F03EFB@stomp.stomp.tokyo>
Have you noticed comp.infosystems.www.authoring.cgi
is now a moderated newsgroup?
You cannot post there unless you provide a valid email
address and respond to mail from authoring-cgi@boutell.com
via your vaild email address.
Personal privacy, avoiding spam email and Freedom of Speech
are struck down, once again.
Not surprising there are a handful of regulars here whom
would have this group moderated as well.
Godzilla!
--
$_="478558535575555150";
tr/873514/975318642abcdef/;
s/([0-9A-Fa-f]{2})/sprintf("%c",hex($1))/ge;
tr// H-OV-ZP-UA-G/;
print$_=reverse$_;exit;
------------------------------
Date: 04 Aug 2001 00:10:48 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: comp.infosystems.www.authoring.cgi now moderated
Message-Id: <m13d785mh3.fsf@halfdome.holdit.com>
>>>>> "Godzilla!" == Godzilla! <godzilla@stomp.stomp.tokyo> writes:
Godzilla!> Have you noticed comp.infosystems.www.authoring.cgi
Godzilla!> is now a moderated newsgroup?
"now"? I believe it has been moderated for at least four years,
probably longer.
Godzilla!> You cannot post there unless you provide a valid email
Godzilla!> address and respond to mail from authoring-cgi@boutell.com
Godzilla!> via your vaild email address.
That's really not too much to ask.
Godzilla!> Personal privacy, avoiding spam email and Freedom of Speech
Godzilla!> are struck down, once again.
Freedom of Speech does not mean that you get to use someone else's
printing press freely. Usenet is a cooperative anarchy... we've got
collective rules here to make things work. The mechanism of a
moderated group is just one aspect of it. You don't like that, you
are free to post in alt.* where it's a bit more of the wild west.
--
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: Sat, 04 Aug 2001 08:09:40 GMT
From: Jeff Thies <cyberjeff@sprintmail.com>
Subject: Re: comp.infosystems.www.authoring.cgi now moderated
Message-Id: <3B6BADA7.D16C91A3@sprintmail.com>
> Godzilla!> Have you noticed comp.infosystems.www.authoring.cgi
> Godzilla!> is now a moderated newsgroup?
>
> "now"? I believe it has been moderated for at least four years,
> probably longer.
>
> Godzilla!> You cannot post there unless you provide a valid email
> Godzilla!> address and respond to mail from authoring-cgi@boutell.com
> Godzilla!> via your vaild email address.
I wouldn't mind any of that, if only my posts would actually post there.
I think their system is if not somewhat broken, is at least erratic. I
haven't seen an email from "authoring-cgi@boutell.com" for some time
(years), so I assume I'm on their "pass me" list. Did I make their
killfile? It's all a mystery to me.
I tend to take my CGI questions to CIWAH or alt.perl. I'd *rather* ask
them in the right group.
Jeff
(who has never used a munged email and hopefully has never crossed the
Usenet Gods)
------------------------------
Date: Sat, 04 Aug 2001 01:18:28 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: comp.infosystems.www.authoring.cgi now moderated
Message-Id: <3B6BAFD4.E7EBFC5F@stomp.stomp.tokyo>
Randal L. Schwartz wrote:
> >>>>> Godzilla! wrote:
> Godzilla!> Have you noticed comp.infosystems.www.authoring.cgi
> Godzilla!> is now a moderated newsgroup?
> "now"? I believe it has been moderated for at least four years,
> probably longer.
No Randal, it was self-moderated. It is no longer. You must
register wtih boutell.com to attain permission to post. This
former "passme" method has been removed and it appears previously
registered addresses have been deleted.
Do you recall a call for public vote to amend the group's charter?
I do not.
> Godzilla!> You cannot post there unless you provide a valid email
> Godzilla!> address and respond to mail from authoring-cgi@boutell.com
> Godzilla!> via your vaild email address.
> That's really not too much to ask.
Read this again:
"Personal privacy, avoiding spam email and Freedom of Speech
are struck down, once again."
> Freedom of Speech does not mean that you get to use someone else's
> printing press freely.
I understand. Your belief is USENET is not open and free for all
to use but rather each newsgroup belongs to its sponsor who can,
at whim and will, impose any conditions and restrictions.
Should Greg Bacon decide only CGI.pm will be discussed here?
If the CLPM Troll, who has persisted for several years in
trying to gain authoritarian control over this group, should
The Troll bend Bacon's ear and impose a rule no newbies will
be allowed to post here, which is one of The Troll's goals.
Obviously The Troll resorts to anything, literally anything,
to prevent me from posting here. So, Greg Bacon decides any
postings originating from SuperNews will not be allowed.
Your personal philosophy supports these types of actions.
My presumption is you, as a former USENET administrator, do not
support USENET traditions and its founding principle, democratic
ideals, such as popular vote to modify a group's charter.
> Usenet is a cooperative anarchy... we've got collective
> rules here to make things work.
Those rules include granting permission to a group sponsor
a power to impose restrictions, independently? It is my
understanding a group sponsor volunteers to host a group
and adamantly agrees to not interfere with its operation
and charter. My opinion is those sponsors whom violate
the sancity of USENET, display a lack of good ethics.
> The mechanism of a moderated group is just one aspect of it.
The charter for the cgi group indicates self-moderation and
provides a methodology for this so all can post. This is
no longer true. Boutell has imposed restrictions of his own,
in violation of the group's charter and in violation of
long standing USENET traditions.
> You don't like that, you are free to post in alt.* where it's
> a bit more of the wild west.
I don't like that. I don't take much of a hankering to those
whom decide use an iron fist approach to administration of a
newsgroup. I have an even dimmer view of those whom support
these dictorial approaches and do not support USENET traditions.
Godzilla!
------------------------------
Date: Sat, 04 Aug 2001 18:53:39 +1000
From: Walnut <walnut@froggy.com.au>
Subject: Re: Database Problem
Message-Id: <vqllmt8npohqkltlm8bupu04srshbq44ht@4ax.com>
On 24 Jul 2001 08:00:08 -0700, tommyumuc@aol.com (JR) wrote:
>
> my $typeChange = $q->param('typeChange');
This should change all the newlines to spaces.
my $typeChange = $q->param('typeChange') =~ s/\n*/\s/g;
------------------------------
Date: 4 Aug 2001 08:03:18 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: Extract the relative sorting of items from multiple lists
Message-Id: <9kga86$g8b$1@news.panix.com>
In article <slrn9mbhmm.d4m.abigail@alexandra.xs4all.nl>,
Abigail <abigail@foad.org> wrote:
>Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCCLXXXVII
>September MCMXCIII in <URL:news:9jrqfi$mp8$1@mamenchi.zrz.TU-Berlin.DE>:
...
>||
>|| There's a module for that!
>||
>|| Well, not quite, but Abigail's Algorithm::Graphs::TransitiveClosure
>|| can play a part.
>
>Yeah, if you have 5 elements or so.
>
>The transitive closure is calculated using a cubed algorithm (you can do
>it a bit faster using complicated techniques, but the best know algorithm
>is still N^e, for some 2.5 < e < 3).
I believe the standard (and ingenious) "Strong Components"
algorithm is or order N, ie linear; just a couple of DFS passes
through a DFS spanning-tree, plus playing around with a stack.
Although that linearity *might* be for only a sparse graph.
Anyway, Topological order is a byproduct of this.
>
>What Bart needs is a topological sort. And you are right, there is a
>module for that. The Graph module, as found on CPAN and discussed in
>"Mastering Algorithms with Perl" has such a method.
>
Some of the more nifty algorithms in that Aho, Ullman, etc
algorithms book (way back when) somehow didn't make
into that perl book. (Pretty much every algorithms
book SINCE the aho/ullman book also has them).
David
------------------------------
Date: Sat, 04 Aug 2001 06:17:01 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How do I manipulate arrays of bits?
Message-Id: <xrMa7.20$T3.171057152@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
How do I manipulate arrays of bits?
Use pack() and unpack(), or else vec() and the bitwise operations.
For example, this sets $vec to have bit N set if $ints[N] was set:
$vec = '';
foreach(@ints) { vec($vec,$_,1) = 1 }
And here's how, given a vector in $vec, you can get those bits into your
@ints array:
sub bitvec_to_list {
my $vec = shift;
my @ints;
# Find null-byte density then select best algorithm
if ($vec =~ tr/\0// / length $vec > 0.95) {
use integer;
my $i;
# This method is faster with mostly null-bytes
while($vec =~ /[^\0]/g ) {
$i = -9 + 8 * pos $vec;
push @ints, $i if vec($vec, ++$i, 1);
push @ints, $i if vec($vec, ++$i, 1);
push @ints, $i if vec($vec, ++$i, 1);
push @ints, $i if vec($vec, ++$i, 1);
push @ints, $i if vec($vec, ++$i, 1);
push @ints, $i if vec($vec, ++$i, 1);
push @ints, $i if vec($vec, ++$i, 1);
push @ints, $i if vec($vec, ++$i, 1);
}
} else {
# This method is a fast general algorithm
use integer;
my $bits = unpack "b*", $vec;
push @ints, 0 if $bits =~ s/^(\d)// && $1;
push @ints, pos $bits while($bits =~ /1/g);
}
return \@ints;
}
This method gets faster the more sparse the bit vector is. (Courtesy of
Tim Bunce and Winfried Koenig.)
Here's a demo on how to use vec():
# vec demo
$vector = "\xff\x0f\xef\xfe";
print "Ilya's string \\xff\\x0f\\xef\\xfe represents the number ",
unpack("N", $vector), "\n";
$is_set = vec($vector, 23, 1);
print "Its 23rd bit is ", $is_set ? "set" : "clear", ".\n";
pvec($vector);
set_vec(1,1,1);
set_vec(3,1,1);
set_vec(23,1,1);
set_vec(3,1,3);
set_vec(3,2,3);
set_vec(3,4,3);
set_vec(3,4,7);
set_vec(3,8,3);
set_vec(3,8,7);
set_vec(0,32,17);
set_vec(1,32,17);
sub set_vec {
my ($offset, $width, $value) = @_;
my $vector = '';
vec($vector, $offset, $width) = $value;
print "offset=$offset width=$width value=$value\n";
pvec($vector);
}
sub pvec {
my $vector = shift;
my $bits = unpack("b*", $vector);
my $i = 0;
my $BASE = 8;
print "vector length in bytes: ", length($vector), "\n";
@bytes = unpack("A8" x length($vector), $bits);
print "bits are: @bytes\n\n";
}
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
04.51
--
This space intentionally left blank
------------------------------
Date: 3 Aug 2001 21:10:33 -0700
From: anthony_barker@hotmail.com (Anthony_Barker)
Subject: Re: frustrated beginner's question
Message-Id: <899f842.0108032010.4f45ce57@posting.google.com>
Thanks Anno!
> Why do you want to sort the data? That is much too much work when
> you only want to mark duplicates. You don't even have to read all
> the data at once.
You are right ... I thought that I would have to read all the records
into an multi-dimensional array in memory and loop through them. Your
solution is much simplier. They are infact already in an type of array
- just in the file.
> During the first pass we generate keys from the name and the beginning
> of the first name. We glue them together with some separator that
> can't appear in a name, so that "Ann Osiegel" and "Anno Siegel" don't
> coalesce. These we store in a hash and count the number of occurrences,
> so we will know on the second pass if we have a duplicate.
>
> The second pass simply looks for duplicates and mail addresses with
> a digit in them and flags all those. Code example below.
---- snip-
> my ( $first, $last) = ( split /,/)[ 2, 3];
> $seen{ substr( $first, 0, 3) . $separator . $last}++; # mark as seen
data going into the hash looks like "fir:lastname"
what does the ++ do in this case?
Hashes I guess don't have to have unique values... (I thought they
did...)
----snip second part---
>
> my ( $first, $last, $addr) = ( split /,/)[ 2, 3, 4];
> if ( $seen{ substr( $first, 0, 3) . $separator . $last} > 1 or
> $addr =~ /\d/ ) {....}
matching hash from the first read through... fairly clear
The code worked great. I modified it to read and write to/from files
instead of from the __DATA__ field... excellent .. thanks!
Yours,
Anthony
------------------------------
Date: Sat, 04 Aug 2001 04:39:58 GMT
From: tuxy <perlgirl@cfl.rr.com>
Subject: how can I permanently change @INC?
Message-Id: <3B6B45A7.9A173F40@cfl.rr.com>
I realize I can push @INC,$newdir and it works nicely on a case-by-case
basis, but how can I change the default value of @INC? I tried perdoc -q
@INC but I don't see an answer there.
Thank-You,
PG
------------------------------
Date: Sat, 04 Aug 2001 08:29:18 GMT
From: blah@blah.blah.invalid
Subject: Re: how can I permanently change @INC?
Message-Id: <ynOa7.167$613.44334150@newssvr17.news.prodigy.com>
You can recompile perl and put 'em in then, or you can add paths
to your PERLLIB or PERL5LIB environment variables (see the perlrun
manpage).
tuxy <perlgirl@cfl.rr.com> wrote:
> I realize I can push @INC,$newdir and it works nicely on a case-by-case
> basis, but how can I change the default value of @INC? I tried perdoc -q
> @INC but I don't see an answer there.
>
> Thank-You,
> PG
------------------------------
Date: Sat, 04 Aug 2001 18:53:41 +1000
From: Walnut <walnut@froggy.com.au>
Subject: Re: How do I make sure I get all form fields and values?
Message-Id: <isnlmtktkau8lp43b7nanlgkbr56bcsula@4ax.com>
On Sun, 29 Jul 2001 16:41:38 -0400, Benjamin Goldberg
<goldbb2@earthlink.net> wrote:
> Eric Bohlman wrote:
> >
> > M Hunt <mhunt5@nospam.net> wrote:
> > > I'm writing out a CSV file which contains all the names and values
> > > submitted from a form. My question is: for checkboxes and/or fields
> > > that were not answered, I get nothing back. This considered, how do
> > > I maintain the integrity of my fields in the CSV. What I need to do
> > > is somehow append a ", NULL" or something when fields are not filled
> > > in. This gets difficult when nothing is returned; with a checkbox
> > > for example.
> >
> > > Also, I just saw in another thread where someone was saying that I
> > > can't even count on the form fields being returned in a particular
> > > order. How is this typically handled -- anyone with a code sample
> > > or something?
-------------------------------------------------------------
Don't reinvent the wheel. Go to http://www.bignosebird.com/cgi.shtml
to get a script called "bnbform" which will show you how to do this
and give you more ideas.
-------------------------------------------------------------
------------------------------
Date: 4 Aug 2001 09:21:35 GMT
From: "~greg" <gm@magpage.com>
Subject: Re: How do I select a random element from an array?
Message-Id: <9kgeqv$iqa$0@216.155.32.129>
> +
> How do I select a random element from an array?
>
> Use the rand() function (see the rand entry in the perlfunc manpage):
>
> # at the top of the program:
> srand; # not needed for 5.004 and later
Isn't that a fault? - not that srand is now in rand()
but the apparent lack of a way to use an explicit
seed to generate the same random sequence
over again when the sequence is being used
to test a program. Or is there a way?
~greg
------------------------------
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 1440
***************************************