[19304] in Perl-Users-Digest
Perl-Users Digest, Issue: 1499 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 11 21:05:58 2001
Date: Sat, 11 Aug 2001 18:05:09 -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: <997578309-v10-i1499@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 11 Aug 2001 Volume: 10 Number: 1499
Today's topics:
Re: 3 very easy ones 4 u (Martien Verbruggen)
Re: CGI.pm --> open FILE,">>file.txt"; <somewhere@in.paradise.net>
Color Coding Lexer for Editor <noway@nohow.com>
FAQ: How can I set up a footer format to be used with w <faq@denver.pm.org>
Re: How to get stderr and stdout of a subprocess? <Tassilo.Parseval@post.rwth-aachen.de>
Re: How to get stderr and stdout of a subprocess? <krahnj@acm.org>
Re: How to get stderr and stdout of a subprocess? <Tassilo.Parseval@post.rwth-aachen.de>
Re: how to test $X le 'z' <krahnj@acm.org>
Re: how to test $X le 'z' <bwalton@rochester.rr.com>
Re: how to test $X le 'z' <linux.gadget.guy@home.com>
Re: how to test $X le 'z' (Abigail)
Re: how to test $X le 'z' <krahnj@acm.org>
Output to New HTML Window <rickayres@email.com>
Re: Output to New HTML Window <tony_curtis32@yahoo.com>
Re: Output to New HTML Window <rickayres@email.com>
Re: perl - write text file to server help (Martien Verbruggen)
Re: perldoc is like Greek to a beginner?? (Anno Siegel)
Re: perldoc is like Greek to a beginner?? <exoelnag@zrqvnbar.arg.INVALID>
Re: permuting extremely large string <godzilla@stomp.stomp.tokyo>
Quick question: do Parse::Recdescent-style grammars for <ekliao@hotmail.com>
Re: Replying to posts <somewhere@in.paradise.net>
Re: Unexplained process killing <bwalton@rochester.rr.com>
Re: Unexplained process killing (Logan Shaw)
Re: voodoo cookie hash problem (Mongo)
wanna call subroutine without package identifier... <murat.uenalan@gmx.de>
Re: What happened to the first element of my arrray? <Pcmann1@btinternet.com>
Re: Writing to a file in another directory <somewhere@in.paradise.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 12 Aug 2001 11:05:33 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: 3 very easy ones 4 u
Message-Id: <slrn9nblit.cq.mgjv@martien.heliotrope.home>
On Sat, 11 Aug 2001 04:41:43 -0400,
Benjamin Goldberg <goldbb2@earthlink.net> wrote:
>
> Using glob("*") is an easy way to get all of the current directory.
Not entirely. glob("*") does not include file names that start with a
dot. glob("*") does the same expansion as csh would do...
glob(".* *") will show a few more file names, specifically . and .. on
Unices, and most directories on DOS-derived systems.
Martien
--
Martien Verbruggen |
Interactive Media Division | Unix is user friendly. It's just
Commercial Dynamics Pty. Ltd. | selective about its friends.
NSW, Australia |
------------------------------
Date: Sun, 12 Aug 2001 08:08:49 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: Re: CGI.pm --> open FILE,">>file.txt";
Message-Id: <E2id7.3$KY5.383080@news.interact.net.au>
"Andras Malatinszky" <andras@mortgagestats.com> wrote in message
news:3B73F1A7.8E63534F@mortgagestats.com...
>
>
> Eric Bohlman wrote:
>
> > Stephen Edelblut <viper16336@mindspring.com> wrote:
> > > My cgi script saves data entered on a form to file.txt (using CGI.pm).
It
> > > works fine, but it only sends it to /cgi_bin/file.txt where the cgi
script
> > > is located. I want it to send it to a file.txt in my root directory
(or some
> > > other folder other that my cgi_bin directory). The code I'm using is:
> > > open FILE,">>file.txt";
> > > How do I change ">>file.txt" if I want it to open
> > > www.mysite.com/textfile/file.txt? Currently file.txt is in my cgi_bin
> > > directory. Whatever I try never works.
> >
> > You find out what actual *directory* the *URL* you gave maps to, and
then
> > include its path in the filename. Remember that URLs are *not*
filesystem
> > paths.
>
> One way to do that is to look at the DOCUMENT_ROOT environment variable,
which
> should give you the full absolute path to the directory that your URL is
mapped
> to. Try
DOCUMENT_ROOT environment variable is not supported by all webservers and is
not part of the CGI spec.
>
> open FILE, ">>$ENV{DOCUMENT_ROOT}/textfile/file.txt";
>
> It is generally a good idea to check the return value of open, and it
would be
> extra useful in your situation.
It is ALWAYS a good idea to check the return value of an open.
------------------------------
Date: Sun, 12 Aug 2001 00:27:59 GMT
From: "Buck Turgidson" <noway@nohow.com>
Subject: Color Coding Lexer for Editor
Message-Id: <j4kd7.102565$J37.24941116@typhoon.southeast.rr.com>
I want to use a CodeWright editor for Perl. I can do color-coding,
formatting, etc if I build a lexer. Has someone done this before, and
would be willing to share it with me.
Or, does someone know of a keyword list for Perl, so I can build my
own?
This is an example of what I am after:
[ChromaLexer-C++]
ChromaFlags=CHROMA_CF_MAIN,0x00000003,1
ChromaFlags=CHROMA_CF_STRING,0x00001d05,1
ChromaAddNumber=0x00000204,'0x','0-9a-fA-F'
ChromaAddNumber=0x80000202,'0','0-7'
ChromaAddNumber=0x00000203,'','0-9'
ChromaIdentifiers='_A-Za-z _A-Za-z0-9'
ChromaBraceChars='{}'
ChromaAddComment=0x00002000,0,"/*","*/"
ChromaAddComment=0x00001000,0,"//"
ChromaAddWords=CHROMA_WT_KEYWORD __asm __based __cdecl __cs __declspec
__ds __es __except __export __far __fastcall __finally __huge __import
__inline __int16
ChromaAddWords=CHROMA_WT_KEYWORD __int32 __int64 __int8 __interrupt
__leave __loadds __multiple_inheritance __near __pascal __rtti
__saveregs __seg __single_inheritance __ss __stdcall __thread
------------------------------
Date: Sun, 12 Aug 2001 00:17:01 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How can I set up a footer format to be used with write()?
Message-Id: <1Wjd7.48$V3.191995904@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 can I set up a footer format to be used with write()?
There's no builtin way to do this, but the perlform manpage has a couple
of techniques to make it possible for the intrepid hacker.
-
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.
05.08
--
This space intentionally left blank
------------------------------
Date: Sun, 12 Aug 2001 00:18:28 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: How to get stderr and stdout of a subprocess?
Message-Id: <3B75AF34.1090801@post.rwth-aachen.de>
Roy Smith wrote:
> I want to run a shell command and capture (separately) both the stdout and
> stderr. Short of mucking about with fork()/exec() myself, if there any way
> to do this? The one example I found was to do:
>
> system ("command > /tmp/stdout 2> /tmp/stderr")
>
> and then open /tmp/std{out,err} and read them back one at a time. This
> would work, but seems kind of clunky. Anything better?
>
You can use the three standard-streams as filehandle in the
open-function. The below will redirect STDERR to a file. The output to
STDOUT is then also written to STDERR. So you have both.
If you do 'perldoc -f open' you'll find an example of how to redirect
both stderr and stdout to a file.
#! /usr/bin/perl -w
use strict;
my $command = $ARGV[0];
open STDERR, ">$command.err"
or die "Error: Could not redirect to $command.err: $!";
print STDERR `$command`;
close STDERR or die "Could not close $command.err: $!"; # 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: Sat, 11 Aug 2001 22:25:22 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: How to get stderr and stdout of a subprocess?
Message-Id: <3B75B0D2.B7B81AD8@acm.org>
Roy Smith wrote:
>
> I want to run a shell command and capture (separately) both the stdout and
> stderr. Short of mucking about with fork()/exec() myself, if there any way
> to do this? The one example I found was to do:
>
> system ("command > /tmp/stdout 2> /tmp/stderr")
>
> and then open /tmp/std{out,err} and read them back one at a time. This
> would work, but seems kind of clunky. Anything better?
perldoc -q "How can I capture STDERR from an external command"
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sun, 12 Aug 2001 00:30:47 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: How to get stderr and stdout of a subprocess?
Message-Id: <3B75B217.7060800@post.rwth-aachen.de>
Tassilo von Parseval wrote:
> Roy Smith wrote:
>
>> I want to run a shell command and capture (separately) both the stdout
>> and stderr. Short of mucking about with fork()/exec() myself, if
>> there any way to do this? The one example I found was to do:
>>
>> system ("command > /tmp/stdout 2> /tmp/stderr")
>>
>> and then open /tmp/std{out,err} and read them back one at a time.
>> This would work, but seems kind of clunky. Anything better?
>>
>
> You can use the three standard-streams as filehandle in the
> open-function. The below will redirect STDERR to a file. The output to
> STDOUT is then also written to STDERR. So you have both.
> If you do 'perldoc -f open' you'll find an example of how to redirect
> both stderr and stdout to a file.
>
> #! /usr/bin/perl -w
> use strict;
> my $command = $ARGV[0];
> open STDERR, ">$command.err"
> or die "Error: Could not redirect to $command.err: $!";
> print STDERR `$command`;
> close STDERR or die "Could not close $command.err: $!"; # well...
> Tassilo
>
Just as an addition, since I saw you wanted the output in two separate
files:
stderr will even then be redirected to "$command.err" if you don't do
this print-statement. The above print will print stdout since backticks
only capture this stream and not stderr. So just open a second
filehandle and print to this.
--
$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: Sat, 11 Aug 2001 22:22:56 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: how to test $X le 'z'
Message-Id: <3B75B03E.C0A8B534@acm.org>
john prokopek wrote:
>
> I seem to be having a problem testing for the value of a character
> variable.
> the code is as follows
>
> for ( $letter = 'a' ; $letter le 'z'; $letter++)
> {
> print $letter."\n";
> }
>
> Now I would think this would print the letters a to z but
> instead it prints a to zz.
>
> What am I doing wrong?
>
> thanks for the help
That's funny why it doesn't work, could be a bug in the string-wise
relational operators. Anyway, the "Perlish" way to do it is:
for my $letter ( 'a' .. 'z' ) {
print "$letter\n";
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 11 Aug 2001 22:49:47 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: how to test $X le 'z'
Message-Id: <3B75B6AB.F29EE7CA@rochester.rr.com>
john prokopek wrote:
>
> I seem to be having a problem testing for the value of a character
> variable.
> the code is as follows
>
> for ( $letter = 'a' ; $letter le 'z'; $letter++)
> {
> print $letter."\n";
> }
>
> Now I would think this would print the letters a to z but
> instead it prints a to zz.
>
> What am I doing wrong?
...
> --
> John D. Prokopek
> jprokopek@snet.net
Why would you think that? Perl is functioning perfectly according to
the documentation and what one would expect. Specifically:
'a' le 'z' is true
'b' le 'z' is true
...
'y' le 'z' is true
'z' le 'z' is true
'aa' le 'z' is true
'bb' le 'z' is true
...
'yz' le 'z' is true
'zz' le 'z' is false
How about $letter ne 'aa'?
--
Bob Walton
------------------------------
Date: Sat, 11 Aug 2001 23:06:43 GMT
From: Fred Richards <linux.gadget.guy@home.com>
Subject: Re: how to test $X le 'z'
Message-Id: <3B75BA91.4060607@home.com>
john prokopek wrote:
>I seem to be having a problem testing for the value of a character
>variable.
>the code is as follows
>
>for ( $letter = 'a' ; $letter le 'z'; $letter++)
>{
> print $letter."\n";
>}
>
>
>Now I would think this would print the letters a to z but
>instead it prints a to zz.
>
>What am I doing wrong?
>
>thanks for the help
>
>
Ugly ... but here goes :-D
#!/usr/bin/perl
for ( $letter = 0x61 ; chr($letter) le 'z'; $letter++)
{
print chr($letter)."\n";
}
Fred Richards
The Gadget Guy
------------------------------
Date: 11 Aug 2001 23:09:50 GMT
From: abigail@foad.org (Abigail)
Subject: Re: how to test $X le 'z'
Message-Id: <slrn9nbeqn.9sn.abigail@alexandra.xs4all.nl>
John W. Krahn (krahnj@acm.org) wrote on MMCMII September MCMXCIII in
<URL:news:3B75B03E.C0A8B534@acm.org>:
:: john prokopek wrote:
:: >
:: > I seem to be having a problem testing for the value of a character
:: > variable.
:: > the code is as follows
:: >
:: > for ( $letter = 'a' ; $letter le 'z'; $letter++)
:: > {
:: > print $letter."\n";
:: > }
:: >
:: > Now I would think this would print the letters a to z but
:: > instead it prints a to zz.
:: >
:: > What am I doing wrong?
:: >
:: > thanks for the help
::
:: That's funny why it doesn't work, could be a bug in the string-wise
:: relational operators. Anyway, the "Perlish" way to do it is:
::
:: for my $letter ( 'a' .. 'z' ) {
:: print "$letter\n";
:: }
It's indeed a bug. It shouldn't go all the way to 'zz', but not further
than 'yz'. (Which is does on all the versions of Perl I tested this with).
That is goes to 'yz' isn't a bug at all. It works as documented. If
you apply ++ on strings, 'z' becomes 'aa'. Now, both 'z' and 'aa' are
(string wise) less or equal to 'z'. The first sequence that isn't is
'za', the one after 'yz'.
Abigail
--
perl -wle 'eval {die ["Just another Perl Hacker"]}; print ${$@}[$#{@${@}}]'
# Two flying larks. Master
# Po dies under a birch
# tree. Mumon laughs.
------------------------------
Date: Sun, 12 Aug 2001 00:35:38 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: how to test $X le 'z'
Message-Id: <3B75CF5A.E4740769@acm.org>
Fred Richards wrote:
>
> john prokopek wrote:
>
> >I seem to be having a problem testing for the value of a character
> >variable.
> >the code is as follows
> >
> >for ( $letter = 'a' ; $letter le 'z'; $letter++)
> >{
> > print $letter."\n";
> >}
> >
> >
> >Now I would think this would print the letters a to z but
> >instead it prints a to zz.
> >
> Ugly ... but here goes :-D
>
> #!/usr/bin/perl
>
> for ( $letter = 0x61 ; chr($letter) le 'z'; $letter++)
> {
> print chr($letter)."\n";
> }
I think you mean :-)
for ( $letter = ord 'a'; $letter <= ord 'z'; $letter++ ) {
print chr( $letter ) . "\n";
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 11 Aug 2001 23:28:19 GMT
From: "Rick Ayres" <rickayres@email.com>
Subject: Output to New HTML Window
Message-Id: <ncjd7.3115$ZM2.300458@newsread2.prod.itd.earthlink.net>
Anyone know of a way to cause the output from a Perl script to appear in a
new HTML window (browser)?
Any help would be greatly appreciated!!
Rick
------------------------------
Date: 11 Aug 2001 18:33:21 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Output to New HTML Window
Message-Id: <873d6ycgu6.fsf@limey.hpcc.uh.edu>
>> On Sat, 11 Aug 2001 23:28:19 GMT,
>> "Rick Ayres" <rickayres@email.com> said:
> Anyone know of a way to cause the output from a Perl
> script to appear in a new HTML window (browser)?
> Any help would be greatly appreciated!!
comp.infosystems.www.authoring.cgi
(caveat programmer)
hth
t
--
Beep beep! Out of my way, I'm a motorist!
------------------------------
Date: Sun, 12 Aug 2001 00:26:18 GMT
From: "Rick Ayres" <rickayres@email.com>
Subject: Re: Output to New HTML Window
Message-Id: <K2kd7.3083$Kl2.316112@newsread1.prod.itd.earthlink.net>
Gotcha.
Thanx.
"Tony Curtis" <tony_curtis32@yahoo.com> wrote in message
news:873d6ycgu6.fsf@limey.hpcc.uh.edu...
> >> On Sat, 11 Aug 2001 23:28:19 GMT,
> >> "Rick Ayres" <rickayres@email.com> said:
>
> > Anyone know of a way to cause the output from a Perl
> > script to appear in a new HTML window (browser)?
>
> > Any help would be greatly appreciated!!
>
> comp.infosystems.www.authoring.cgi
>
> (caveat programmer)
>
> hth
> t
> --
> Beep beep! Out of my way, I'm a motorist!
>
------------------------------
Date: Sun, 12 Aug 2001 10:56:29 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: perl - write text file to server help
Message-Id: <slrn9nbl1t.cq.mgjv@martien.heliotrope.home>
On Sat, 11 Aug 2001 00:49:48 -0700,
benhopkins@mindspring.com <benhopkins@mindspring.com> wrote:
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>
><snip>
>
>>> As there don't seem to be any off the shelf solutions for this Perl
>>> script i will need a program written.
>
>> Then I would fire up my editor, and start programming. Alternatively,
>> you can open your wallet, and ire a Perl programmer.
>
> Uh, ahem, I, uh, think he's already done the
> last thing you mentioned.
Heh, yeah, he made me really lose my h.
Martien
--
Martien Verbruggen |
Interactive Media Division | If at first you don't succeed, try
Commercial Dynamics Pty. Ltd. | again. Then quit; there's no use
NSW, Australia | being a damn fool about it.
------------------------------
Date: 11 Aug 2001 22:07:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <9l4abp$ll9$1@mamenchi.zrz.TU-Berlin.DE>
According to Mark Jason Dominus <mjd@plover.com>:
> In article <3b74127b.86043433@news.compuserve.com>,
> <MSherrill@compuserve.com> wrote:
> >When I read that, it dawned on me that I don't know *any* syntax for
> >regular expressions besides the Unix-ish derivatives. What are the
> >alternatives on other platforms?
>
> Regular expressions predate unix, and the notation hasn't varied much
> since they were invented. (Originally by neurologists describing the
> behavior of state machines(!!)) The original conception only had
> concatenation *, and |, and used + in place of |, but it's the same
> idea. When Ken Thompson showed in 1968 that regexes could be used to
> describe an effective pattern matching language, he followed the
> existing notation. He then incorporated his idea into Unix.
Thanks for that short history of the regex language. I was vaguely
aware of parts of it but couldn't think of a source to fill the gaps.
Is there one?
> >*Are* there alternatives on other platforms?
>
> Consider the unix and DOS shell languages for matching filenames:
>
> a*.jp?
>
> is equivalent to the regex /^a.*\.jp.$/
>
> Very few systems have the same power as regexes. People occasionally
> propose notations like this:
>
> <regex>
> <start-anchor/>
> <literal value="a">
> <star><anychar /></star>
> <literal value=".jp">
> <anychar />
> <end-anchor/>
> </regex>
>
> but as far as I know none has even been implemented until just
> recently because there wasn't enough stupidity stockpiled in one place
> to make it seem like a good idea.
Yikes. One day everything will look like HTML.
I do remember using an editor long ago which had a quite different
pattern language. I don't recall if it approached the full regex
repertoire, it might have been some variant of wildcard matching.
"Ediere" had the useful concept of matching in "context", which came
in left and right variants corresponding to our lookbehind and
lookahead. Parentheses were used to separate "context patterns"
from consuming (and captured) "text patterns", and people used them
all the time.
In another thread Uri has stressed the usefulness of lookarounds in
regexes. It is unfortunate that they are unintuitively named and
awkwardly syntaxed.
Anno
------------------------------
Date: Sun, 12 Aug 2001 00:20:27 GMT
From: Rob Bryant <exoelnag@zrqvnbar.arg.INVALID>
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <MPG.15df6ba1d191ac0f989699@nntp.we.mediaone.net>
In article <3b758a29.125$2c7@news.op.net>, Mark Jason Dominus
<mjd@plover.com> wrote:
> The only benefit that the
> XML version appears to have is that it doesn't look like Lisp, which
> everyone thinks they hate.
>
Incorrect. Some of us KNOW that we hate Lisp.
-Rob
--
Remove ".INVALID" and ROT-13 for email address.
------------------------------
Date: Sat, 11 Aug 2001 16:02:19 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: permuting extremely large string
Message-Id: <3B75B97B.1038AA2@stomp.stomp.tokyo>
Godzilla! wrote:
> Godzilla! wrote:
(might be snipped again)
> > Here are four methods which took me fifteen to twenty minutes
> > to develop and test, blank page start to finish.
> WAIT!!!!
> I recall a person claiming a Perl programmer can
> only write ten lines of code per day. He even put
> up a pretty good impotent fight, citing inane author
> references and similar such mule manure.
> * blows smoke off her finger tips *
> Amazing, ain't I?
This time I typed with both my fingers and toes.
AHHHHHHHhhhhhh!!! My toes are on fire!
Godzilla! Queen Of Twentyone.
--
#!perl
print "Content-type: text/plain\n\n";
$samples = 10;
$string = "Godzilla Rocks and Rolls! Oh yes! She Rocks My Socks Off!";
$string = " $string ";
if (length ($string) > 1000)
{ print "Do This Yourself, Bozo!"; exit; }
if ($samples > 100)
{ print "Do This Yourself, Bozo!"; exit; }
do
{
$position = index ($string, " ", $position);
push (@Array, $position);
$position++;
}
until ($position == rindex ($string, " ") + 1);
print "$string\n\n";
for ($iterate1 = 0; $iterate1 <= $samples; $iterate1++)
{ &FYS (\@Array); }
sub FYS
{
$control = "$random @Array";
if (length ($control > 100000))
{ print "\n\n\nI Am Tired Of Doing This. You Do It, Bozo!"; }
do
{
$array = shift;
for ($iterate2 = @$array; --$iterate2; )
{
$rand = int rand ($iterate2 + 1);
next if $iterate2 == $rand;
@$array[$iterate2, $rand] = @$array[$rand, $iterate2];
}
$random = "@Array";
}
until (index ($control, $random) == -1);
for (@Array)
{
$snatch = substr ($string, $_, index ($string, " ", $_ + 1) - $_);
print $snatch;
}
print "\n";
}
------------------------------
Date: 11 Aug 2001 19:05:06 -0500
From: Eric Liao <ekliao@hotmail.com>
Subject: Quick question: do Parse::Recdescent-style grammars for parsing Java and C++ code exist?
Message-Id: <nlhbntgk5t3201so5d8cfqfo7qvlbof3f8@4ax.com>
------------------------------
Date: Sun, 12 Aug 2001 08:27:06 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: Re: Replying to posts
Message-Id: <Njid7.4$YF5.111726@news.interact.net.au>
"Chas Friedman" <friedman@math.utexas.edu> wrote in message
news:3b744276$1_1@feed1.realtime.net...
> When attempting to reply to a post, I often get an error message to the
> effect
> that the reply was not sent because there is more included (quoted) text
> than new text. Is this set by the newsgroup? (It doesn't seem to be
anything
> set by my mail server.) Thanks for any comments!
It's purely a function of your news reader, in attempt to inject a modicum
of newsettique into its users (at least what it thinks is newsettique).
Take note that Usenet and mail and two entirely different things. They are
not related to each other.
------------------------------
Date: Sat, 11 Aug 2001 22:55:45 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Unexplained process killing
Message-Id: <3B75B810.8994E1D4@rochester.rr.com>
Moran Goldstein wrote:
>
> Hi,
> I'm working on a script that loops through large arrays and modifies
> numeric values. Specifically, hashes of 3D-arrays (ie -
> $hash{key}[Z][Y][X]). The problem is that, depending on the size of
> the array, it's likely to get killed(running on FreeBSD). The arrays
> can get up to 200,000 values, usually of floating-point numbers.
...
> -Moran Goldstein
You probably should ask your system administrator if there are any
process limits in effect on the system on which you are running. You
could also try your program on other systems, like a Linux or Windoze PC
or something, where you know such interference is not happening, and see
if the problem goes away. There should not be anything in Perl that
would cause this.
--
Bob Walton
------------------------------
Date: 11 Aug 2001 18:17:25 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Unexplained process killing
Message-Id: <9l4ee5$csv$1@charity.cs.utexas.edu>
In article <223f9ce4.0108111237.4ddde3a6@posting.google.com>,
Moran Goldstein <moran-gy@actcom.co.il> wrote:
>I'm working on a script that loops through large arrays and modifies
>numeric values. Specifically, hashes of 3D-arrays (ie -
>$hash{key}[Z][Y][X]). The problem is that, depending on the size of
>the array, it's likely to get killed(running on FreeBSD). The arrays
>can get up to 200,000 values, usually of floating-point numbers.
>
>I'm guessing that the script is being killed because of memory usage,
>but I can't be sure.
:
:
>When it gets killed, it just says "killed", with no details. Is there
>any way I can get more information from the script about why it's
>being killed?
The script or Perl interpreter probably isn't the one that's doing the
killing. It's probably the FreeBSD kernel. Usually Perl says
"Out of memory!" if it asks for memory and can't get any.
Why this is happening is hard to say. One possibility is that your
kernel uses a memory management policy that overcommits memory
allocation. I don't know much about FreeBSD, but I seem to recall at
least AIX has this option. Basically, what this amounts to is that
when you do a malloc(), the kernel reserves the address space for your
process, but doesn't actually reserve virtual memory. It is only when
you use the memory itself and the MMU and page table actually map it to
something that the memory is really allocated. I have long since
forgotten how to change this setting on AIX, or even what it's called.
The reason for this feature is that many applications waste lots of
memory (i.e. allocate it and never use it). You can deal with this in
two ways: either prevent processes from running because they claim they
need a lot of memory when they really don't, or allow them to run and
take the chance that you might have to kill a process when the system
is running low on memory. If I remember correctly, the behavior under
AIX was to find the process with the largest memory usage and kill that
one in an effort to keep the whole system running.
Of course, this is just one possible explanation. I suggest you
ask on a FreeBSD newsgroup to get a better idea.
> Any error-checking methods? Also, isn't 200,000 values
>actually a small amount, relative to the huge amounts of database
>strings Perl so easily deals with?
In Perl, there is a certain overhead for storing a scalar value. If
you store a small number of really large scalar values, you don't incur
much overhead relative to the amount of data you're storing. But if
you store a large number of small scalar values (floating point numbers
definitely count), you will have a very high overhead.
Also, "multi-dimensional" arrays have a fairly high overhead in Perl,
because actually true multi-dimensional arrays don't exist, and instead
they are arrays of references to arrays. If you store a 2 x 3 x 4
array in a conventional language like C, it will require just the space
required for 24 elements. In Perl, you will have an array of two
references to arrays; both of these will be to an array of size three
full of references to arrays of size four. This means you'll have a
total of 9 arrays, 8 references, and 24 regular elements. All of these
things are going to have overhead. Also, I don't know the specifics of
Perl, but my guess is that even small arrays will be allocated from a
fixed-size block of memory.
Here's some code to demonstrate this:
#! /usr/local/bin/perl
$threedim = 128;
$onedim = $threedim * $threedim * $threedim;
print "one or three?\n";
$response = <>;
if ($response =~ /three/)
{
print "doing three dimensional\n";
for ($i = 0; $i < $threedim; $i++)
{
for ($j = 0; $j < $threedim; $j++)
{
for ($k = 0; $k < $threedim; $k++)
{
$a[$i][$j][$k] = 3.14159;
}
}
}
}
if ($response =~ /one/)
{
print "doing one dimensional\n";
for ($i = 0 ; $i < $onedim ; $i++)
{
$a[$i] = 3.14159;
}
}
print "done; hit return.\n";
$response = <>;
When waiting at the first prompt, "top" on my system shows the perl
process using 2212K of memory. If I type "one", then at the second
prompt it is using 52MB meaning that it takes 50MB to store that those
2^21 values in a one-dimensional array. If I type "three", then at the
second prompt its size grows 62MB instead, meaning it uses 60 MB to
store those same values. (The amount of extra memory used depends on
the size of the individual dimensions as well.)
Actually, the most important point is that it really takes a LOT of
memory to store these values either way you do it. 50 MB is 52428800
bytes, and if that's used to store 2^21 values, that means that each
value (each floating point number) is using 25 bytes. The machine
representation of a double normally takes only 8 bytes, so you can see
that there's lots of overhead.
What I would suggest is that you use some of your operating system's
tools (like maybe "top" or "ps") to watch the process and see how large
it grows. You may be surprised. To get more detail, you might step
through your program in the Perl debugger and watch the memory (using
something like "top") at various stages.
Either that, or there's always the standard answer of "add more swap
space." :-)
- Logan
--
"Our grandkids love that we get Roadrunner and digital cable."
(Advertisement for Time Warner cable TV and internet access, July 2001)
------------------------------
Date: 11 Aug 2001 16:58:51 -0700
From: mongo@firewallx.com (Mongo)
Subject: Re: voodoo cookie hash problem
Message-Id: <dc31dfbf.0108111558.6cf64280@posting.google.com>
Here is the code, maybe someone else can see somthing. When I try to
put one of these env or cookie values into an email it ends up as a
blank space??
%cookies = &getCookies;
&getCookies;
&sendmessage;
exit;
########################################
sub getCookies {
local(@rawCookies) = split (/; /,$ENV{'HTTP_COOKIE'});
local(%cookies);
foreach(@rawCookies){
($key, $val) = split (/=/,$_);
$cookies{$key} = $val;
}
return %cookies;
}
########################################
sub sendmessage{
my $from = "jojo\@dancer.com";
$to = "gigi\@dancer.com";
$Subject = "some subject";
$vari2 = "$cookies{email}";
$vari3 = $ENV{'HTTP_COOKIE'};
open MAIL, "| $mailprogram -t -oi $adminemail ";
print MAIL <<EOMH;
Reply-to: $from
From: $from
To: $to
Subject: $Subject
EOMH
print MAIL <<ENDNO;
Here is another test!\n\n
$vari2<br>
$vari3 \n\n\n
ENDNO
print MAIL <<EOMF;
football
$ENV{'REMOTE_HOST'}<br>
$ENV{'HTTP_COOKIE'}<br>
$cookies{email}<br>\n\n\n
EOMF
close MAIL;
}
------------------------------
Date: Sun, 12 Aug 2001 00:56:01 +0200
From: "Murat Uenalan" <murat.uenalan@gmx.de>
Subject: wanna call subroutine without package identifier...
Message-Id: <9l4d0d$7fgjr$1@ID-71895.news.dfncis.de>
Hi folks,
i just want to call a function from every package (like the builtin
functions). I also want it to be used without need for brackets '()'. Here
the significant code...
__PERL__
package Class;
#Exporter stuff ....
sub import
{
*CORE::GLOBAL::class = \&class;
}
sub class
{
}
1;
__END__
When called anywhere like this it fails.
use Class;
class( blablabla );
package FOO;
class( blabla );
------------------------------
Date: Sat, 11 Aug 2001 23:16:41 +0100
From: "Peter Mann" <Pcmann1@btinternet.com>
Subject: Re: What happened to the first element of my arrray?
Message-Id: <9l4aqs$dk8$1@neptunium.btinternet.com>
Thankyou!!
I would like to thank both of you for your time and effort for explaining my
faulty code. It makes much more sense now. Once again Thankyou!
Regards
- Pete
"gnari" <gnarinn@hotmail.com> wrote in message
news:997559128.99941075919196.gnarinn@hotmail.com...
> In article <9l3i2m$aoj$1@neptunium.btinternet.com>,
> Peter Mann <Pcmann1@btinternet.com> wrote:
>
> > I am new to Perl and this problem has me puzzled. When I call
'output
> >users' from 'getUsers' the first element of the array is missing and not
> >displayed in the combo box!
> > Before i split it up into 2 subs, all the elements were displayed in
> >the combo box, so I suspect the problem has something to do with passing
the
> >array? But what is it?
> >
> >
> >
> >
> >sub getUsers
> >{
> > $dbh = DBI->connect('dbi:ODBC:developers');
> > $sqlstatement = "SELECT * FROM developers";
>
> i will assume that developers contains only one field
> you should use named fields instead of the '*', otherwise you will
> get bitten later
>
> >
> > $sth = $dbh->prepare($sqlstatement);
> > $sth->execute ||
> > die "Could not execute SQL statement, maybe invalid?";
> >
> > @users=$sth->fetchrow_array;
>
> ok you have fetched first user into @user
>
> > outputUsers (@users);
> >
> > $sth->finish();
> > $dbh->disconnect();
> >}
> >
> >
> >sub outputUsers
> >{
>
> at this point @_ contains one user
> > my @temp = shift;
>
> (strange syntax) here you put the user into @temp,
> and as this is not used any more, you have effectively thrown it away
> maybe you wanted to insert it into the combo?
>
> >
> > #Output database results
> > while ($temp=$sth->fetchrow_array)
> > {
> > $combo1->insert("end", $temp);
> > }
> >}
> >
>
> probably what you want is:
>
> remove the fetchrow_array from getUsers()
> change the call outputUsers(@users) to outputUsers();
> remove the shift line in outputUsers()
>
> while you are at it , i would:
> not use globals for $sth and $combo1 and $dbh
> change the while line to: while (my ($temp)=$sth->fetchrow_array)
>
> (all this untested, so look out for typos and such)
>
> good luck
> gnari
>
------------------------------
Date: Sun, 12 Aug 2001 08:31:10 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: Re: Writing to a file in another directory
Message-Id: <Anid7.5$GH5.205937@news.interact.net.au>
"sowbug" <brianwharris@hotmail.com> wrote in message
news:c5d7d22b.0108102137.6274c6dd@posting.google.com...
> Does anybody know the correct syntax for writing to a file in another
> directory besides the one you are currently in. Using a Unix server
> with apache. I'm trying to write to a html file that's in htdocs from
> the script which is in the cgi-bin directory. Do the forward slashes
> have to be escaped? I've tryed almost every thing I can think of.
> Thanx in advance.
Just specify the directory you want to write to, eg:
open FILE,'>/some/dir/with/the/file' or die "Can not write to
/some/dir/with/the/file $!\n";
------------------------------
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 1499
***************************************