[10554] in Perl-Users-Digest
Perl-Users Digest, Issue: 4146 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 4 09:08:03 1998
Date: Wed, 4 Nov 98 06:00:23 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 4 Nov 1998 Volume: 8 Number: 4146
Today's topics:
Re: A nifty regex trick (David Cantrell)
Can Perl make Web Browser show arbitrary file? <qrajrhd@era.ericsson.se>
Re: FAQ question. (David Cantrell)
Re: Help -- Need Sybperl (Rich)
Help please <joseluis@idirect.com>
Re: HELP! I need a perl enviroment for Win 95 <bill@fccj.org>
Re: How does a function know if its being called inside <zenin@bawdycaste.org>
How to insert PERL commands in a ASP page ? alphaque@my-dejanews.com
How to strip Local URL's and IMG's from files? (Paulo Jorge Matos - LEI)
I can not get my 'Hello World' CGI-Script in Perl to wo (Lutz R|hmann)
Re: I can not get my 'Hello World' CGI-Script in Perl t (Tore Aursand)
Re: More flushing buffer to STDOUT rabisteve@my-dejanews.com
Re: Newbie: files in different directories. dave@mag-sol.com
Re: Opendir <sigh> again <ewinter@pop3.stx.com>
Re: Opendir <sigh> again (David Alan Black)
perl debugger + emacs question <eedalf@eed.ericsson.se>
Re: PERL is TOO flexible <perlguy@technologist.com>
perl newbie desperate question <ours@casema.net>
Re: perl&cgi question <bill@fccj.org>
programing fun: tree: Transpose <xah@best.com>
Re: programing fun: tree: Transpose <xah@best.com>
Re: programing fun: tree: Transpose <kjetil@balder.no>
que regarding perl&C interface <dhami@ecn.purdue.edu>
Quiz type form.... <james.bartlett@bt-sys.bt.co.uk>
redirect output (Warren Miller)
Stopped Connection <mackr@rbg.ul.bw.schule.de>
Re: Stopped Connection <Tony.Curtis+usenet@vcpc.univie.ac.at>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 04 Nov 1998 10:09:35 GMT
From: NukeEmUp@ThePentagon.com (David Cantrell)
Subject: Re: A nifty regex trick
Message-Id: <36402745.403632643@thunder>
On Tue, 03 Nov 1998 20:00:56 GMT,
mcafee@waits.facilities.med.umich.edu (Sean McAfee) enlightened us
thusly:
>Recently I realized that since regex patterns are interpolated in the same
>way that strings are, one could do this instead:
>
>@options = qw/ foo bar baz bletch /;
>
>$" = "|"; # wrap in block and make local if necessary
>while (<>) {
> print $1 if /(@options)/o;
>}
>
>I don't believe I've seen this idiom anywhere before. Just thought
>I'd share!
I do that in a small web search engine. You should be aware that your
use of /o means that the regex will only be interpolated ONCE, so if
you try to execute that code a second time with different stuff in
@options then it will actually match against whatever was in @options
the first time round.
[Copying newsgroup posts to me by mail is considered rude]
--
David Cantrell, part-time Unix/perl/SQL/java techie
full-time chef/musician/homebrewer
http://www.ThePentagon.com/NukeEmUp
------------------------------
Date: Wed, 04 Nov 1998 14:56:23 +0100
From: Jerker Haglund <qrajrhd@era.ericsson.se>
Subject: Can Perl make Web Browser show arbitrary file?
Message-Id: <36405D07.EACFCA95@era.ericsson.se>
On the Win NT DOS command line you can type in a URL to
make the default browser (netscape or ie) display it. If
the browser is running a new one is not started.
How can I do the same from a perl script? "system" and
back-tick does not seem to work (perhaps the DOS-shell
has to be interactive?). As an addition I would also
like to display text files (.txt).
Thanks, /J. Haglund
------------------------------
Date: Wed, 04 Nov 1998 10:13:21 GMT
From: NukeEmUp@ThePentagon.com (David Cantrell)
Subject: Re: FAQ question.
Message-Id: <36422882.403949438@thunder>
On Tue, 03 Nov 1998 15:11:24 +0100, Kjetil Svendsberget
<kjetil@balder.no> enlightened us thusly:
>I have a question which i didnt find at language.perl.com/faq
>which MUST be a faq.
>
>How do i remove carrige returns from a file copied from winblows to
>unix?
The easiest way (that is, without even touching vi or perl) is to
transfer the file using ftp, in TEXT mode as opposed to BINARY mode.
[Copying newsgroup posts to me by mail is considered rude]
--
David Cantrell, part-time Unix/perl/SQL/java techie
full-time chef/musician/homebrewer
http://www.ThePentagon.com/NukeEmUp
------------------------------
Date: 4 Nov 1998 13:10:10 GMT
From: richm@ucesucks.mulveyr.roc.servtech.com (Rich)
Subject: Re: Help -- Need Sybperl
Message-Id: <slrn740kgt.r7.richm@ll.aa2ys.ampr.org>
On Sat, 31 Oct 1998 23:17:27 -0500, Matthew O. Persico <mpersico@erols.com> wrote:
>> That is the most backward policy I have seen in a long time!
>>
>
>WHAT the HELL is their rationale for THAT policy? And yes, I do know
>that I am yelling.
>
In most cases of this sort, the admins are too lazy to actually
support the users/developers who they should be helping. The solution,
of course, is to start climbing the org chart and ask, "Why are the
admins making decisions on development toolsets?"
- Rich
--
Rich Mulvey
My return address is my last name,
followed by my first initial, @mulveyr.roc.servtech.com
http://mulveyr.roc.servtech.com
Amateur Radio: aa2ys@wb2wxq.#wny.ny.usa
------------------------------
Date: Wed, 4 Nov 1998 08:26:48 -0500
From: "Idirect" <joseluis@idirect.com>
Subject: Help please
Message-Id: <364056dc.0@nemo.idirect.com>
I have a *.db file from a program, I need to convert this file to be read in
access or filemaker. How do I extract the text from it, or convert into
another extension other than *.db?
please e-mail to joseluis@idirect.com
------------------------------
Date: Wed, 04 Nov 1998 06:40:55 -0500
From: Bill Jones <bill@fccj.org>
Subject: Re: HELP! I need a perl enviroment for Win 95
Message-Id: <36403D47.32B3E949@fccj.org>
Cornuts wrote:
>
> Jonathan Stowe wrote:
> >
> > On Mon, 02 Nov 1998 17:56:49 -0800 Cornuts <cornuts@mrfoda.com> wrote:
> > > Does anyone know where I can download software to program in perl
> > > besides CPAN and Active state. I have searched around and found those
> > > two sites as the only ones who actually distribute perl software
> > > (enviroments) I have downloaded from both of those sites and found
> > > "uncleanable" viruses in each.
> >
> > I would trade in the virus checker for something better.
> >
> > /J\
> > --
> > Jonathan Stowe <jns@btinternet.com>
> > Some of your questions answered:
> > <URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
>
> Ok why does nobody believe me? I found two macro viruses ( Microsoft
> Word). I have run into one of them before "Word Stress" it scrambled all
> the text around in my word files. My virus scanner caught this and
> another macro virus. The viruses are there so I'm not making it up. I
> also need to download a new virus pattern though.
No viruses, not in the perl distribution. I bet you had them all
along and just think they showed up in the perl distrbutions. Or...
Your virus checker is giving you a false positive.
Trust Jonathan and get a NEW virus checker.
Otherwise, send the virus signatures to me and I'll be happy to
follow-up for you. On a side note, it's not that I don't believe you,
but I've downloaded code this past Monday from both places and I
have yet to find a virus in them - darn it all...
HTH,
-Sneex- :]
________________________________________________________________________
Bill Jones | FCCJ Webmaster | x3089 | http://webmaster.fccj.org:81
------------------------------------------------------------------------
__ _ RedHat 5.1 Manhatten
/ /(_)_ __ _ ___ __ http://www.apache.org
/ / | | '_ \| | | \ \/ / http://www.redhat.com
/ /__| | | | | |_| |> < http://www.perl.com
\____/_|_| |_|\__,_/_/\_\ http://www.gimp.org
------------------------------
Date: 04 Nov 1998 11:28:09 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: How does a function know if its being called inside eval {} ?
Message-Id: <910178883.708559@thrush.omix.com>
mlehmann@prismnet.com wrote:
: I am trying to write backwards compatible object libraries.
Eval has been in Perl since version 1. There is no backwards
compatibility to worry about except within your own interface.
: I would like to use exceptions in my constructors, but only if my
: constructors are inside an eval. The die command seems to know if it is
: inside and eval and does different actions depending on its context. I
: basically want to do the same thing, but I do not see how die is doing this.
Not quite. The eval is doing the magic here, by trapping all fatal
errors.
You'll also run into many other problems. The eval might be from
an autoload. It would be from a timeout. They may well know that
your constructor throws an exception and are actually counting on
it by *not* wrapping it in eval. I think lamba functions also think
they are an "eval", when it comes to the stack trace.
Two good ways to handle constructor failure:
Throw an exception and document this fact in the pod. It is then
up to the user to trap it or not, as it should be.
Return undef and set $@ to your error message, similar to above.
This style lets the user throw the exception if they want to:
my $obj = Object->new () or die; ## $@ automatically propregated
--
-Zenin (zenin@archive.rhps.org) From The Blue Camel we learn:
BSD: A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts. Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.) The full chemical name is "Berkeley Standard Distribution".
------------------------------
Date: Wed, 04 Nov 1998 09:46:12 GMT
From: alphaque@my-dejanews.com
Subject: How to insert PERL commands in a ASP page ?
Message-Id: <71p7p4$3ol$1@nnrp1.dejanews.com>
Hi.. May I know is there any way for me to insert some PERL commands in the
ASP pages ? If yes, what is the syntax and do I need to install the PERL
interpreter in my IIS server because I don't think the ASP interpreter can
understand the PERL command.. Any help ? Thanks
rgds.Fok
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 4 Nov 1998 11:25:37 GMT
From: pjsm@students.si.fct.unl.pt (Paulo Jorge Matos - LEI)
Subject: How to strip Local URL's and IMG's from files?
Message-Id: <71pdjh$e6e$1@news.si.fct.unl.pt>
Hi!
I'm having trouble finding a perl script that, based on HTML files
searching could:
- Extract all local files;
- This includes all references to local files, i. e, all HREF's to
local files and all IMG's to local files... (and any other that I might have
forget).
I am positive that this kind of script has already been done, and
it's public somewhere. However, until now, I could only find this kind of
scripts based on _URL's_ and I'm looking for it based on _FILES_.
Appreciate some directions,
Thanks in Advance
Paulo Matos
---------------------------------- --------------------------------------
|Computer Science Student | |
|Faculty of Science and Technology | e-Mail: pjsm@students.fct.unl.pt |
|New University of Lisbon | |
|PORTUGAL | |
---------------------------------- --------------------------------------
------------------------------
Date: 1 Nov 1998 11:00:25 GMT
From: Fernsicht@t-online.de (Lutz R|hmann)
Subject: I can not get my 'Hello World' CGI-Script in Perl to work on my Server.
Message-Id: <71hf09$icf$1@news01.btx.dtag.de>
Hello,
my name is Lutz R|hmann, and i'm a beginner in writing cgi scripts
with perl. It would be great if you could help me out with this.
I have tried for several days to get my first script to work on
my server, but it didn't happen.
Below you see the script, the error and what else i did.
Everything remains at the server as it is now, so you can look at it.
My e-Mail address is: Fernsicht@T-Online.de
You can look at this site to have a link to the scripts.
http://www.zunker.de/cgicall.htm
Thank Y'all
Lutz
---------------------------------------------------------------------------------------------------------------
This error occured.
---------------------------------------------------------------------------------------------------------------
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator, webmaster@zunker.de and inform
them of the time the error occurred, and anything
you might have done that may have caused the error.
---------------------------------------------------------------------------------------------------------------
I tried renaming lutz.pl into lutz.cgi. Both are saved at cgi-bin.
And both doesn't work.
The files are chmod so everyone can read and execute them.
I was told,
"This is the Path to where you can install cgi-scripts.
The real Paths are:
/usr/local/etc/httpd/htdocs/zunker/cgi-zunker/
Path to Perl 5: /usr/bin/perl
---------------------------------------------------------------------------------------------------------------
The following CGI script was succesfully lokaly interpreted on my
computer.
---------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl/
print 'Content-type: text/html ', "\n";
print '<html> ', "\n";
print '<body> ', "\n";
print 'Hello World ', "\n";
print '</body> ', "\n";
print '</html> ', "\n";
exit (0);
---------------------------------------------------------------------------------------------------------------
------------------------------
Date: Wed, 04 Nov 1998 13:20:50 GMT
From: tore@forumnett.no (Tore Aursand)
Subject: Re: I can not get my 'Hello World' CGI-Script in Perl to work on my Server.
Message-Id: <36405477.680216299@news.online.no>
On 1 Nov 1998 11:00:25 GMT, Fernsicht@t-online.de (Lutz R|hmann)
wrote:
> print 'Content-type: text/html ', "\n";
Should rather be:
print("Content-type: text/html\n\n");
--
Tore Aursand
ForumNett Online AS
http://www.forumnett.no/
------------------------------
Date: Wed, 04 Nov 1998 11:51:38 GMT
From: rabisteve@my-dejanews.com
Subject: Re: More flushing buffer to STDOUT
Message-Id: <71pf4a$dai$1@nnrp1.dejanews.com>
Hello again,
I have been having the same problem described below with the output going to a
file.
The file is not written to until I close the link from the server.
Steve
In article <71nt9e$bof$1@nnrp1.dejanews.com>,
rabisteve@my-dejanews.com wrote:
> Hello News people,
>
> I am constructing a script which communicates via tcpip
>
> I am not Mr. Scripter so you can flame me now.
>
> At any rate the other computer which I am communicating with is sending a
> response. I know this because I see it in its log. Additionally, when the
> other computer (which happens to be running OpenVMS) cuts communications I
> see the contents printed out on the Standard Output
>
> I understand that this may be a problem with flushing the buffer the script
> below (whihc I downloaded from somewhere) seems to do this:
>
> select(S); $| = 1; select(STDOUT);
>
> The massage from the Open VMS does not have line endings or anything
> conveinent like that.
>
> I would really appreciate and give a blessing to whomever tells me where to
> stick another one of these flushers so that I can see the text as it is sent
> from Mr OpenVMS
>
> The more specific the information the more helpful it will be. I often take
> stupid pills. This puts me on the level of the people I must assist.
>
> BTW - the Perl script is runmmimg perl 5004 on an an Alpha running Diigtal
> unix 4b (I believe)
>
> Thanks,
> Steve
>
> #!/usr/bin/perl
>
> #binds the port
>
> ($them,$port) = @ARGV;
> $port = 2345 unless $port;
> $them = 'localhost' unless $them;
>
> $AF_INET = 2;
> $SOCK_STREAM = 1;
>
> $SIG{'INT'} = 'dokill';
> sub dokill {
> kill 9,$child if $child;
> }
>
> $sockaddr = 'S n a4 x8';
>
> chop($hostname = `hostname`);
>
> ($name,$aliases,$proto) = getprotobyname('tcp');
> ($name,$aliases,$port) = getservbyname($port,'tcp')
> unless $port =~ /^\d+$/;;
> ($name,$aliases,$type,$len,$thisaddr) =
> gethostbyname($hostname);
> ($name,$aliases,$type,$len,$thataddr) = gethostbyname($them);
>
> $this = pack($sockaddr, $AF_INET, 0, $thisaddr);
> $that = pack($sockaddr, $AF_INET, $port, $thataddr);
>
> # Make the socket filehandle.
>
> if (socket(S, $AF_INET, $SOCK_STREAM, $proto)) {
> print "socket ok\n";
> }
> else {
> die $!;
> }
>
> # Give the socket an address.
>
> if (bind(S, $this)) {
> print "bind ok\n";
> }
> else {
> die $!;
> }
>
> # Call up the server.
>
> if (connect(S,$that)) {
> print "connect ok\n";
> }
> else {
> die $!;
> }
>
> # Set socket to be command buffered.
>
> select(S); $| = 1; select(STDOUT);
>
> # Avoid deadlock by forking.
>
> if($child = fork) {
> while (<STDIN>) {
> print S;
> }
> sleep 3;
> do dokill();
> }
> else {
> while(<S>) {
> print;
> }
> }
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 04 Nov 1998 09:50:10 GMT
From: dave@mag-sol.com
Subject: Re: Newbie: files in different directories.
Message-Id: <71p80h$3ql$1@nnrp1.dejanews.com>
In article <363F596A.73147E19@control.auc.dk>,
Morten Knudsen <mk@control.auc.dk> wrote:
[snipped, Christian's problem and my potential solution]
> Thank you for your help, but I'm still at a loss. I've prepended(?) the
> path to the file when defining $cart and I've also chmoded the /carts
> directory to 766, so the user should be able to read/write the cart file.
>
> I'm also pretty sure that it _is_ the correct path to the cart file, so
> I just can't figure out where the problem is...
If you post your current code together with the errors that you're getting,
then we might be able to help you some more. If you open the file as I
suggested in my last post, i.e.
open (CART, "$dir/$file") or die "Can't open $dir/$file: $!\n";
then the script will die and write a (hopefully) useful message in you error
log.
hth,
Dave...
--
dave@mag-sol.com
London Perl M[ou]ngers: <http://london.pm.org/>
[Note Changed URL]
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 4 Nov 1998 06:06:59 -0500
From: "Eric Winter" <ewinter@pop3.stx.com>
Subject: Re: Opendir <sigh> again
Message-Id: <71pck3$e3@post.gsfc.nasa.gov>
Ahh, but do you also have the execute bit set for group/other on every
directory in the path? That's needed in order to see the contents of any
directory...
Patrick Taylor wrote in message <36400747.7A3CE789@gmp.usyd.edu.au>...
>directory name it returns is valid). i'ce made the file owned by, and
>run by, root.
>
>Any clues for the clueless?
HTH
Eric
------------------------------
Date: 4 Nov 1998 06:39:45 -0500
From: dblack@pilot.njin.net (David Alan Black)
Subject: Re: Opendir <sigh> again
Message-Id: <71pee1$40i$1@pilot.njin.net>
Patrick Taylor <alpaca@gmp.usyd.edu.au> writes:
>i've checked through Dejanews for all the posts on this but no one seems
>to have had exactly the same problem.....
>i got a very simple script that lists files from a list of directories
>and prints the full file names. It gets to the opendir command and
>returns the "Cannot open..." (and yep, the directories do exist, and the
>directory name it returns is valid). i'ce made the file owned by, and
>run by, root.
>Any clues for the clueless?
>#!/usr/local/bin/perl -w
>$rootdir="/usr/local/web/docs";
>open ( LIST, "list" ) ;
>while (<LIST>){
chomp;
[etc.]
David Black
dblack@pilot.njin.net
------------------------------
Date: Wed, 04 Nov 1998 11:48:56 +0100
From: Alexander Farber <eedalf@eed.ericsson.se>
Subject: perl debugger + emacs question
Message-Id: <36403118.AFC1DFDA@eed.ericsson.se>
Hi,
I am using the perl debugger (the -d switch) and it is very good.
But now I have a small problem when using it within xemacs:
my perl script requires some input from STDIN. I enter it, but
how do I return back to the debugger in order to proceed?? The
debugger does not execute the commands (like n) any more - it looks
like it waits for more input. ^D does not help either.
Thank you in advance!
Greetings
Alex
------------------------------
Date: Wed, 4 Nov 1998 12:53:08 GMT
From: Brent Michalski <perlguy@technologist.com>
Subject: Re: PERL is TOO flexible
Message-Id: <36404E34.4F44704A@technologist.com>
In article <3638676E.F980FC4A@harris.com>,
PERL ROCKS! <emills@harris.com> wrote:
> "Although the Perl Slogan is There's More Than One Way to Do It, I
> hesitate to make 10 ways to do something. :-) "
> --Larry Wall in <9695@jpl-devvax.JPL.NASA.GOV>
>
>is along these lines- why make more than ONE? What did it add, Larry?
Wow, I *HAD* to comment on this "ONE" (pun intended)
Why on earth would you want only ONE way to do something in a
language?!??!
What if Larry's idea of defining a variable was something like:
"String to define" ----> STRING_NAME_~~~{(*this is my variable*)}~~~
(Sorry Larry, I know you aren't likely to do it this way, well I hope
not.) ;-)
Granted, this is a _stupid_ way to do it, but who is to say that "way x"
is better than "way y"?
What if there was only one sort routine in your language? You couldn't
optimize or tweak it, you could only use the one. If it wasn't fast
enough, tough, you can't change it or make it better, it is the ONLY way
to do it.
Hell, what if there was only one road in your country. If it didn't go
to your house, tough. Would you move closer to the road? I'd move to a
different country.
I recommend "finding the box", then learn how to think outside of it. I
find life much better outside the box rather than being confined to the
rigit constraints of the box.
Larry, I LOVE the way Perl lets me do things my way. Perl allows me to
think and work the way my brain does, NOT the way the language _thinks_
I should think.
Brent
P.S. If you __Still__ don't understand what Larry's quote means. My
interpretation is this: There should be more than one way to do
something, but there is also a limit to the number of ways you should be
able to do it. I think Perl has found the "happy medium."
--
Java? I've heard of it, it is what I drink when I am hacking Perl. -me
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$ Brent Michalski $
$ -- Perl Evangelist -- $
$ E-Mail: perlguy@technologist.com $
$ Resume: http://www.inlink.com/~perlguy $
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
------------------------------
Date: Wed, 4 Nov 1998 14:20:36 +0100
From: "Casema" <ours@casema.net>
Subject: perl newbie desperate question
Message-Id: <71pkd4$2eu$1@sun4000.casema.net>
Hi perl programmers,
I downloaded perl from www.perl.com and installed it on my windows98 pc for
testing.
the compiler itself is in c:\perl\bin
what is the code to point to this directory. Al my testing results with the
same output......
The prints are ignored and the HTML is installed.
I cannot use variables, nothing
#!c:\perl\bin\perl does not work.
Please, can someone point me in the right direction?
thanks,
Michel
------------------------------
Date: Wed, 04 Nov 1998 06:44:26 -0500
From: Bill Jones <bill@fccj.org>
Subject: Re: perl&cgi question
Message-Id: <36403E1A.3A1655FF@fccj.org>
Kjetil Svendsberget wrote:
>
> Excuse me for being clueless, but what is a PoB system?
Prisoner of Bill (AKA Windows user.)
As Sun Microsystems said "Open Systems means no fences...
No fences means no use for Gates..."
(Original author unknown.)
HTH,
-Sneex- :]
________________________________________________________________________
Bill Jones | FCCJ Webmaster | x3089 | http://webmaster.fccj.org:81
------------------------------------------------------------------------
__ _ RedHat 5.1 Manhatten
/ /(_)_ __ _ ___ __ http://www.apache.org
/ / | | '_ \| | | \ \/ / http://www.redhat.com
/ /__| | | | | |_| |> < http://www.perl.com
\____/_|_| |_|\__,_/_/\_\ http://www.gimp.org
------------------------------
Date: Wed, 04 Nov 1998 05:29:12 -0700
From: "Xah" <xah@best.com>
Subject: programing fun: tree: Transpose
Message-Id: <36405549$0$29751@nntp1.ba.best.com>
Another fantastically fun programing problem for all you Perl mongers out out there. Looks like I'll be posting one per week to keep you guys entertained. (autotainment too!)
This week's problem is "Transpose". Problem spec is attached below my sig. I'll be posting my solution on Saturday. Gurus, Masters, Experts, please wipe out all the world's eggheads with your Perl code. Out with rigidity. In with lubrication.
By the way, just for fun, and nothing but fun:
Guru: Those who knows the language inside out, including internals. Larry, Tom, Randal are probably gurus.
Master: Those who knows the language thoroughly, or can quickly find out the answers to some niche questions. The knowledge usually include familiarily with most existing libraries and documentations and several books. Many Perl book authors are masters.
Expert: Those who can program with the language with ease. The knowledge includes knowing how to use any library quickly, and knowing all the idioms or the cons and pros of special constructs of the language. Experts probably have read all standard documentations and faqs at least once, and few books too. Perhaps many module writers or folks here are Perl experts.
Masters and mistresses, this semi-expert awaits your lesson. Come on and whip me with your efficacy. I'm chained to the Ivory tower and am in dire need for a good grind.
(^_~)
Xah, xah@best.com
http://www.best.com/~xah/PageTwo_dir/more.html
Petty penguins make way: GNU HURD is coming! <www.gnu.org>
#_____ Transpose _____ _____ _____ _____
=pod
B<Transpose>
Transpose(tree) returns a result that is the given tree with the first two levels transposed. e.g. Transpose( [[1,2,3],['a','b','c']] ) returns [[1,'a'],[2,'b'],[3,'c']].
Transpose(tree, permutationList) transposes the tree according to permutationList of the form [n1,n2,...,nm], where each n_i is a unique positive integer from 1 to m. Transpose( [[1,2,3],['a','b','c']] ) is equivalent to Transpose( [[1,2,3],['a','b','c']], [2,1] ).
Transpose essentially restructures a tree into a different shape. Here are some explanations, examples follows at the end. First, we'll use a simple example to illustrate. Suppose we have $tree = [[1,2,3],['a','b','c']] and $permutationList = [2,1]. The elements at level two of the tree have these position indexes:
element position index
1 [0,0]
2 [0,1]
3 [0,2]
'a' [1,0]
'b' [1,1]
'c' [1,2]
Since the length of $permutationList is two, thus Transpose will reshape the tree at level two. For each node, Transpose will apply the given permutation to its position index. Here's the result:
element position index
1 [0,0]
2 [1,0]
3 [2,0]
'a' [0,1]
'b' [1,1]
'c' [2,1]
Transpose then construct a tree by this new element/index pair. The result is [[1,'a'],[2,'b'],[3,'c']]. Because transposition with permutation [2,1] is common (matrix computations), thus it is the default behavior for Transpose with just one argument.
The given tree needs to be a rectangular array only up to the level m, where m is the length of the specified permutation. For example, suppose we have $tree = [[1,2,3],[$anotherTree,'b','c']] and $permutationList = [2,1]. It all works just as before, except that the element 'a' is substituted by $anotherTree. For example, Transpose([[ 1,2,3],[ ['m','n'] ,'b','c']], [2,1]) returns [[1,['m','n']],[2,'b'],[3,'c']].
Longer permutations also works similarly. For example, suppose
$tree = [ [['x1','x2'],['y1','y2'],['z1','z2']], [ ['a1','a2'] ,['b1','b2'], ['c1','c2']]];
$permutationList = [2,3,1];
Since the length of $permutationList is 3, thus looking at level 3 of the tree we have
element position index
before / after permute by [3,1,2]
'x1' [0,0,0] [0,0,0]
'x2' [0,0,1] [1,0,0]
'y1' [0,1,0] [0,0,1]
'y2' [0,1,1] [1,0,1]
'z1' [0,2,0] [0,0,2]
'z2' [0,2,1] [1,0,2]
'a1' [1,0,0] [0,1,0]
'a2' [1,0,1] [1,1,0]
'b1' [1,1,0] [0,1,1]
'b2' [1,1,1] [1,1,1]
'c1' [1,2,0] [0,1,2]
'c2' [1,2,1] [1,1,2]
Therefore, the result is [[['x1','y1','z1'],['a1','b1','c1']],[['x2','y2','z2'],['a2','b2','c2']]].
There are some implied restrictions on the input to Transpose:
1. The second argument must be a permutation of a range of m numbers that starts with one.
2. The tree must be a rectangular array up to level m. That is, Length(Dimensions($tree)) >= m.
A property of Transpose:
If $tree is a rectangular array, then the following is always true.
Permute(Dimensions($tree), $permutationList) == Dimensions(Transpose($tree, $permutationList))
If $tree is a rectangular array up to level m only, then the left and right hand side agrees up to the first m numbers.
Example:
my $tree =
[
[ ['x1','x2'], ['y1','y2'], ['z1','z2']],
[ ['a1','a2'], ['b1','b2'], ['c1','c2']]
];
Transpose( $tree, [1, 2, 3]);
# returns [[['x1','x2'],['y1','y2'],['z1','z2']],[['a1','a2'],['b1','b2'],['c1','c2']]]
Transpose( $tree, [1, 3, 2]);
# returns [[['x1','y1','z1'],['x2','y2','z2']],[['a1','b1','c1'],['a2','b2','c2']]]
Transpose( $tree, [2, 1, 3]);
# returns [[['x1','x2'],['a1','a2']],[['y1','y2'],['b1','b2']],[['z1','z2'],['c1','c2']]]
Transpose( $tree, [2, 3, 1]);
# returns [[['x1','a1'],['x2','a2']],[['y1','b1'],['y2','b2']],[['z1','c1'],['z2','c2']]]
Transpose( $tree, [3, 1, 2]);
# returns [[['x1','y1','z1'],['a1','b1','c1']],[['x2','y2','z2'],['a2','b2','c2']]]
Transpose( $tree, [3, 2, 1]);
# returns [[['x1','a1'],['y1','b1'],['z1','c1']],[['x2','a2'],['y2','b2'],['z2','c2']]]
=cut
------------------------------
Date: Wed, 04 Nov 1998 05:48:55 -0700
From: "Xah" <xah@best.com>
Subject: Re: programing fun: tree: Transpose
Message-Id: <364059e5$0$29758@nntp1.ba.best.com>
A quick correction:
The line
$permutationList = [2,3,1]
should be
$permutationList = [3,1,2]
Xah, xah@best.com
http://www.best.com/~xah/PageTwo_dir/more.html
Petty penguins make way: GNU HURD is coming! <www.gnu.org>
------------------------------
Date: Wed, 04 Nov 1998 14:58:08 +0100
From: Kjetil Svendsberget <kjetil@balder.no>
Subject: Re: programing fun: tree: Transpose
Message-Id: <36405D6F.220F0860@balder.no>
WHY do you have extremely long lines? Makes it HARD to read
[snip]
------------------------------
Date: Wed, 4 Nov 1998 00:17:13 -0500
From: Dharti Dhami <dhami@ecn.purdue.edu>
Subject: que regarding perl&C interface
Message-Id: <Pine.SOL.3.91.981104001533.8623A-100000-100000-100000@min.ecn.purdue.edu>
Hello,
I am a student at purdue university and i am trying to develop a
web based application in which i need to do the following things
1. Get some information from the web - using Forms on the web page
2. Use this information .
A c program is written to process this information.
I would like to know if it is possible to pass this information to C
program and cause the C program to run and then get the results from this
C program and then display on the web page again.
this is really crucial for me and hence if u could help me out or suggest
a ray of light in this matter, it will be great.
thanks
dharti
--------------------------------------------------------------------------------
Dharti Dhami
101, Russel Street, Appt # 10
West Lafayette, IN -47906
email : dhami@ecn.purdue.edu
Ph : (765)-743-6953
--------------------------------------------------------------------------------
------------------------------
Date: Wed, 04 Nov 1998 10:07:10 +0000
From: James Bartlett <james.bartlett@bt-sys.bt.co.uk>
Subject: Quiz type form....
Message-Id: <3640274E.5DE1A725@bt-sys.bt.co.uk>
This is a multi-part message in MIME format.
--------------0EDB3C820DC53008FAD2D5F0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
I've got a questionnaire form with 9 set's of 3 radio buttons. I want a
page to appear on pressing the submit button that tells the users
whether they've answered Mostly A's, Mostly B's or Mostly C's.
How can this be done??
--------------0EDB3C820DC53008FAD2D5F0
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for James Bartlett
Content-Disposition: attachment; filename="vcard.vcf"
begin: vcard
fn: James Bartlett
n: Bartlett;James
email;internet: james.bartlett@bt-sys.bt.co.uk
x-mozilla-cpt: ;0
x-mozilla-html: FALSE
version: 2.1
end: vcard
--------------0EDB3C820DC53008FAD2D5F0--
------------------------------
Date: 4 Nov 1998 11:06:20 GMT
From: wmiller@mars.cs.unp.ac.za (Warren Miller)
Subject: redirect output
Message-Id: <910177579.775551@mars.cs.unp.ac.za>
Hiya
This program works but at the moment all it does it print the ouput of a
webpage to the screen.
How would I get the info that prints to the screen into a variable?
Thanx
#!/usr/local/bin/perl
use IO::Socket;
$host="mars.cs.unp.ac.za";
$document="index.html";
$remote = IO::Socket::INET->new(Proto =>"tcp",
PeerAddr => $host,
PeerPort => "http(80)",
);
$remote->autoflush(1);
print $remote "GET $document HTTP/1.0\n\n";
while (<$remote>) {print} #This is the problem area
close $remote;
------------------------------
Date: Wed, 04 Nov 1998 11:21:14 +0100
From: Ruediger Mack <mackr@rbg.ul.bw.schule.de>
Subject: Stopped Connection
Message-Id: <36402A9A.21039780@rbg.ul.bw.schule.de>
Hello,
My CGI sends many bytes, and it needs some time for it.
My question:
How do my CGI know that the connection is stopped by the user?
...Ruediger
------------------------------
Date: 04 Nov 1998 11:32:50 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: Stopped Connection
Message-Id: <83ww5bwxws.fsf@vcpc.univie.ac.at>
Re: Stopped Connection, Ruediger <mackr@rbg.ul.bw.schule.de>
said:
Ruediger> Hello, My CGI sends many bytes, and it needs some
Ruediger> time for it. My question: How do my CGI know that
Ruediger> the connection is stopped by the user?
If the connection goes away then the CGI application will
walk into a SIGPIPE signal.
So, assuming this actually has something to do with perl
(you don't mention perl anywhere) you need to set up a
handler for it in the %SIG hash.
hth
tony
--
Tony Curtis, Systems Manager, VCPC, | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien, | <URI:http://www.vcpc.univie.ac.at/>
"You see? You see? Your stupid minds! | private email:
Stupid! Stupid!" ~ Eros, Plan9 fOS.| <URI:mailto:tony_curtis32@hotmail.com>
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 4146
**************************************