[32181] in Perl-Users-Digest
Perl-Users Digest, Issue: 3446 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 18 14:09:25 2011
Date: Mon, 18 Jul 2011 11:09:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 18 Jul 2011 Volume: 11 Number: 3446
Today's topics:
=?UTF-8?Q?a_little_parsing_challenge_=E2=98=BA?= <xahlee@gmail.com>
=?UTF-8?Q?Re=3A_a_little_parsing_challenge_=E2=98=BA?= <python@rcn.com>
=?UTF-8?Q?Re=3A_a_little_parsing_challenge_=E2=98=BA?= <t@jollybox.de>
=?UTF-8?Q?Re=3A_a_little_parsing_challenge_=E2=98=BA?= <python@rcn.com>
=?UTF-8?Q?Re=3A_a_little_parsing_challenge_=E2=98=BA?= <rantingrick@gmail.com>
=?UTF-8?Q?Re=3A_a_little_parsing_challenge_=E2=98=BA?= <xahlee@gmail.com>
Re: a little parsing challenge =?UTF-8?B?4pi6?= <shortcutter@googlemail.com>
Re: a little parsing challenge =?UTF-8?B?4pi6?= <michihenn@hotmail.com>
Re: a little parsing challenge =?UTF-8?B?4pi6?= <shortcutter@googlemail.com>
Re: a little parsing challenge =?UTF-8?B?4pi6?= <shortcutter@googlemail.com>
Re: a little parsing challenge =?UTF-8?Q?=E2=98=BA?= <tboell@domain.invalid>
Re: Cpan problem XML::LibXML with Ubuntu <news@lawshouse.org>
Re: Cpan problem XML::LibXML with Ubuntu <jimsgibson@gmail.com>
Re: Perl Multitasking Question <edgrsprj@ix.netcom.com>
Re: Perl Multitasking Question <ralph@happydays.com>
TZ problem <dave@invalid.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 17 Jul 2011 00:47:42 -0700 (PDT)
From: Xah Lee <xahlee@gmail.com>
Subject: =?UTF-8?Q?a_little_parsing_challenge_=E2=98=BA?=
Message-Id: <36037253-086b-4467-a1db-9492d3772e78@r5g2000prf.googlegroups.com>
2011-07-16
folks, this one will be interesting one.
the problem is to write a script that can check a dir of text files
(and all subdirs) and reports if a file has any mismatched matching
brackets.
=E2=80=A2 The files will be utf-8 encoded (unix style line ending).
=E2=80=A2 If a file has mismatched matching-pairs, the script will display =
the
file name, and the line number and column number of the first
instance where a mismatched bracket occures. (or, just the char number
instead (as in emacs's =E2=80=9Cpoint=E2=80=9D))
=E2=80=A2 the matching pairs are all single unicode chars. They are these a=
nd
nothing else: () {} [] =E2=80=9C=E2=80=9D =E2=80=B9=E2=80=BA =C2=AB=C2=BB =
=E3=80=90=E3=80=91 =E3=80=88=E3=80=89 =E3=80=8A=E3=80=8B =E3=80=8C=E3=80=8D=
=E3=80=8E=E3=80=8F
Note that =E2=80=98single curly quote=E2=80=99 is not consider matching pai=
r here.
=E2=80=A2 You script must be standalone. Must not be using some parser tool=
s.
But can call lib that's part of standard distribution in your lang.
Here's a example of mismatched bracket: ([)], (=E2=80=9C[[=E2=80=9D), ((, =
=E3=80=91etc. (and
yes, the brackets may be nested. There are usually text between these
chars.)
I'll be writing a emacs lisp solution and post in 2 days. =CE=99 welcome
other lang implementations. In particular, perl, python, php, ruby,
tcl, lua, Haskell, Ocaml. I'll also be able to eval common lisp
(clisp) and Scheme lisp (scsh), Java. Other lang such as Clojure,
Scala, C, C++, or any others, are all welcome, but i won't be able to
eval it. javascript implementation will be very interesting too, but
please indicate which and where to install the command line version.
I hope you'll find this a interesting =E2=80=9Cchallenge=E2=80=9D. This is =
a parsing
problem. I haven't studied parsers except some Wikipedia reading, so
my solution will probably be naive. I hope to see and learn from your
solution too.
i hope you'll participate. Just post solution here. Thanks.
Xah
------------------------------
Date: Sun, 17 Jul 2011 02:48:42 -0700 (PDT)
From: Raymond Hettinger <python@rcn.com>
Subject: =?UTF-8?Q?Re=3A_a_little_parsing_challenge_=E2=98=BA?=
Message-Id: <99245842-e205-4a34-8f9d-c64d41e044b6@j9g2000prj.googlegroups.com>
On Jul 17, 12:47=A0am, Xah Lee <xah...@gmail.com> wrote:
> i hope you'll participate. Just post solution here. Thanks.
http://pastebin.com/7hU20NNL
Raymond
------------------------------
Date: Sun, 17 Jul 2011 08:31:33 -0700 (PDT)
From: Thomas Jollans <t@jollybox.de>
Subject: =?UTF-8?Q?Re=3A_a_little_parsing_challenge_=E2=98=BA?=
Message-Id: <7ae55705-6342-4f06-add8-59de05d111b9@x12g2000yql.googlegroups.com>
On Jul 17, 9:47=C2=A0am, Xah Lee <xah...@gmail.com> wrote:
> 2011-07-16
>
> folks, this one will be interesting one.
>
> the problem is to write a script that can check a dir of text files
> (and all subdirs) and reports if a file has any mismatched matching
> brackets.
>
> =E2=80=A2 The files will be utf-8 encoded (unix style line ending).
>
> =E2=80=A2 If a file has mismatched matching-pairs, the script will displa=
y the
> file name, and the =C2=A0line number and column number of the first
> instance where a mismatched bracket occures. (or, just the char number
> instead (as in emacs's =E2=80=9Cpoint=E2=80=9D))
>
> =E2=80=A2 the matching pairs are all single unicode chars. They are these=
and
> nothing else: () {} [] =E2=80=9C=E2=80=9D =E2=80=B9=E2=80=BA =C2=AB=C2=BB=
=E3=80=90=E3=80=91 =E3=80=88=E3=80=89 =E3=80=8A=E3=80=8B =E3=80=8C=E3=80=
=8D =E3=80=8E=E3=80=8F
> Note that =E2=80=98single curly quote=E2=80=99 is not consider matching p=
air here.
>
> =E2=80=A2 You script must be standalone. Must not be using some parser to=
ols.
> But can call lib that's part of standard distribution in your lang.
>
> Here's a example of mismatched bracket: ([)], (=E2=80=9C[[=E2=80=9D), ((,=
=E3=80=91etc. (and
> yes, the brackets may be nested. There are usually text between these
> chars.)
>
> I'll be writing a emacs lisp solution and post in 2 days. =CE=99 welcome
> other lang implementations. In particular, perl, python, php, ruby,
> tcl, lua, Haskell, Ocaml. I'll also be able to eval common lisp
> (clisp) and Scheme lisp (scsh), Java. Other lang such as Clojure,
> Scala, C, C++, or any others, are all welcome, but i won't be able to
> eval it. javascript implementation will be very interesting too, but
> please indicate which and where to install the command line version.
>
> I hope you'll find this a interesting =E2=80=9Cchallenge=E2=80=9D. This i=
s a parsing
> problem. I haven't studied parsers except some Wikipedia reading, so
> my solution will probably be naive. I hope to see and learn from your
> solution too.
>
> i hope you'll participate. Just post solution here. Thanks.
I thought I'd have some fun with multi-processing:
https://gist.github.com/1087682
------------------------------
Date: Sun, 17 Jul 2011 12:16:13 -0700 (PDT)
From: Raymond Hettinger <python@rcn.com>
Subject: =?UTF-8?Q?Re=3A_a_little_parsing_challenge_=E2=98=BA?=
Message-Id: <42a76bcc-c5e7-424e-9373-1ecd8f80df25@y13g2000prb.googlegroups.com>
On Jul 17, 8:49=A0am, Thomas Boell <tbo...@domain.invalid> wrote:
> But why do you enumerate with start=3D1? Shouldn't you start with index 0=
?
The problem specification says that the the char number should match
the emacs goto-char function which is indexed from one, not from
zero. This is testable by taking the output of the program and
running it through emacs to see that the cursor gets moved exactly to
the location of the mismatched delimiter.
Raymond
------------------------------
Date: Sun, 17 Jul 2011 18:52:12 -0700 (PDT)
From: rantingrick <rantingrick@gmail.com>
Subject: =?UTF-8?Q?Re=3A_a_little_parsing_challenge_=E2=98=BA?=
Message-Id: <741a7641-7833-4d51-a17b-548a930b70f4@u26g2000vby.googlegroups.com>
On Jul 17, 2:47=A0am, Xah Lee <xah...@gmail.com> wrote:
> 2011-07-16
>
> folks, this one will be interesting one.
>
> the problem is to write a script that can check a dir of text files
> (and all subdirs) and reports if a file has any mismatched matching
> brackets.
>
>[...]
>
> =95 You script must be standalone. Must not be using some parser tools.
> But can call lib that's part of standard distribution in your lang.
I stopped reading here and did...
>>> from HyperParser import HyperParser # python2.x
...and called it a day. ;-) This module is part of the stdlib (idlelib
\HyperParser) so as per your statement it is legal (may not be the
fastest solution).
------------------------------
Date: Mon, 18 Jul 2011 07:39:28 -0700 (PDT)
From: Xah Lee <xahlee@gmail.com>
Subject: =?UTF-8?Q?Re=3A_a_little_parsing_challenge_=E2=98=BA?=
Message-Id: <87f46fe8-5d1d-4ed0-b6e3-87c5f9262c38@t38g2000prj.googlegroups.com>
On Jul 17, 12:47=C2=A0am, Xah Lee <xah...@gmail.com> wrote:
> 2011-07-16
>
> folks, this one will be interesting one.
>
> the problem is to write a script that can check a dir of text files
> (and all subdirs) and reports if a file has any mismatched matching
> brackets.
> =E2=80=A6
Ok, here's my solution (pasted at bottom). I haven't tried to make it
elegant or terse, yet, seeing that many are already much elegent than
i could possibly do so with my code.
my solution basically use a stack. (i think all of us are doing
similar) Here's the steps:
=E2=80=A2 Go thru the file char by char, find a bracket char.
=E2=80=A2 check if the one on stack is a matching opening char. If so remov=
e
it. Else, push the current onto the stack.
=E2=80=A2 Repeat the above till end of file.
=E2=80=A2 If the stack is not empty, then the file got mismatched brackets.
Report it.
=E2=80=A2 Do the above on all files.
Many elegant solutions. Raymond Hettinger is very quick, posted a
solution only after a hour or so when i posted it. Many others are
very short, very nice. Thank you all for writing them. I haven't
studied them yet. I'll run them all and post a summary in 2 days. (i
have few thousands files to run this test thru, many of them have
mismatched brackets. So i have good data to test with.)
PS we still lack a perl, Scheme lisp, tcl, lua versions. These
wouldn't be hard and would be interesting to read. If you are picking
up one of these lang, this would be a good exercise. Haskell too. I
particularly would like to see a javascript version ran from command
line. Maybe somebody can put this exercise to Google folks ... they
are like the js gods.
also, now that we have these home-brewed code, how'd a parser expert
do it? Is it possible to make it even simpler by using some parser
tools? (have no idea what those lex yacc do, or modern incarnations)
I've also been thinking whether this can be done with Parsing
Expression Grammar. That would make the code semantics really elegant
(as opposed home-cooked stack logic).
Xah
;; -*- coding: utf-8 -*-
;; 2011-07-15, Xah Lee
;; go thru a file, check if all brackets are properly matched.
;; e.g. good: (=E2=80=A6{=E2=80=A6}=E2=80=A6 =E2=80=9C=E2=80=A6=E2=80=9D=E2=
=80=A6)
;; bad: ( [)]
;; bad: ( ( )
(setq inputDir "~/web/xahlee_org/p/") ; must end in slash
(defvar matchPairs '() "a alist. For each air, the car is opening
char, cdr is closing char.")
(setq matchPairs '(
("(" . ")")
("{" . "}")
("[" . "]")
("=E2=80=9C" . "=E2=80=9D")
("=E2=80=B9" . "=E2=80=BA")
("=C2=AB" . "=C2=BB")
("=E3=80=90" . "=E3=80=91")
("=E3=80=88" . "=E3=80=89")
("=E3=80=8A" . "=E3=80=8B")
("=E3=80=8C" . "=E3=80=8D")
("=E3=80=8E" . "=E3=80=8F")
)
)
(defvar searchRegex "" "regex string of all pairs to search.")
(setq searchRegex "")
(mapc
(lambda (mypair) ""
(setq searchRegex (concat searchRegex (regexp-quote (car mypair))
"|" (regexp-quote (cdr mypair)) "|") )
)
matchPairs)
(setq searchRegex (replace-regexp-in-string "|$" "" searchRegex t
t)) ; remove the ending =E2=80=9C|=E2=80=9D
(setq searchRegex (replace-regexp-in-string "|" "\\|" searchRegex t
t)) ; change | to \\| for regex =E2=80=9Cor=E2=80=9D operation
(defun my-process-file (fpath)
"process the file at fullpath fpath ..."
(let (myBuffer (ii 0) myStack =CE=BEchar =CE=BEpos)
(setq myStack '() ) ; each element is a vector [char position]
(setq =CE=BEchar "")
(setq myBuffer (get-buffer-create " myTemp"))
(set-buffer myBuffer)
(insert-file-contents fpath nil nil nil t)
(goto-char 1)
(while (search-forward-regexp searchRegex nil t)
(setq =CE=BEpos (point) )
(setq =CE=BEchar (buffer-substring-no-properties =CE=BEpos (- =CE=BEp=
os 1)) )
;; (princ (format "-----------------------------\nfound char: %s
\n" =CE=BEchar) )
(let ((isClosingCharQ nil) (matchedOpeningChar nil) )
(setq isClosingCharQ (rassoc =CE=BEchar matchPairs))
(when isClosingCharQ (setq matchedOpeningChar (car
isClosingCharQ) ) )
;; (princ (format "isClosingCharQ is: %s\n" isClosingCharQ) )
;; (princ (format "matchedOpeningChar is: %s\n"
matchedOpeningChar) )
(if
(and
(car myStack) ; not empty
(equal (elt (car myStack) 0) matchedOpeningChar )
)
(progn
;; (princ (format "matched this bottom item on stack: %s
\n" (car myStack)) )
(setq myStack (cdr myStack) )
)
(progn
;; (princ (format "did not match this bottom item on
stack: %s\n" (car myStack)) )
(setq myStack (cons (vector =CE=BEchar =CE=BEpos) myStack) ) )
)
)
;; (princ "current stack: " )
;; (princ myStack )
;; (terpri )
)
(when (not (equal myStack nil))
(princ "Error file: ")
(princ fpath)
(print (car myStack) )
)
(kill-buffer myBuffer)
))
;; (require 'find-lisp)
(let (outputBuffer)
(setq outputBuffer "*xah match pair output*" )
(with-output-to-temp-buffer outputBuffer
(mapc 'my-process-file (find-lisp-find-files inputDir "\\.html$"))
(princ "Done deal!")
)
)
------------------------------
Date: Sun, 17 Jul 2011 15:20:25 +0200
From: Robert Klemme <shortcutter@googlemail.com>
Subject: Re: a little parsing challenge =?UTF-8?B?4pi6?=
Message-Id: <98g5spFcm4U1@mid.individual.net>
On 07/17/2011 11:48 AM, Raymond Hettinger wrote:
> On Jul 17, 12:47 am, Xah Lee<xah...@gmail.com> wrote:
>> i hope you'll participate. Just post solution here. Thanks.
>
> http://pastebin.com/7hU20NNL
Ruby solution: https://gist.github.com/1087583
Kind regards
robert
------------------------------
Date: Sun, 17 Jul 2011 15:55:25 +0200
From: mhenn <michihenn@hotmail.com>
Subject: Re: a little parsing challenge =?UTF-8?B?4pi6?=
Message-Id: <4e22e9cd$0$6574$3ca0ca56@newsspool3.vodafone-ip.de>
Am 17.07.2011 15:20, schrieb Robert Klemme:
> On 07/17/2011 11:48 AM, Raymond Hettinger wrote:
>> On Jul 17, 12:47 am, Xah Lee<xah...@gmail.com> wrote:
>>> i hope you'll participate. Just post solution here. Thanks.
>>
>> http://pastebin.com/7hU20NNL
>
> Ruby solution: https://gist.github.com/1087583
I acutally don't know Ruby that well, but it looks like your program
recognizes "[(])" as correct although it is not, because you translate
"[(])" to "(())" (which is indeed correct, but does not resemble the
input correctly anymore).
>
> Kind regards
>
> robert
------------------------------
Date: Sun, 17 Jul 2011 18:01:32 +0200
From: Robert Klemme <shortcutter@googlemail.com>
Subject: Re: a little parsing challenge =?UTF-8?B?4pi6?=
Message-Id: <98gfasFjq2U1@mid.individual.net>
On 07/17/2011 03:55 PM, mhenn wrote:
> Am 17.07.2011 15:20, schrieb Robert Klemme:
>> On 07/17/2011 11:48 AM, Raymond Hettinger wrote:
>>> On Jul 17, 12:47 am, Xah Lee<xah...@gmail.com> wrote:
>>>> i hope you'll participate. Just post solution here. Thanks.
>>>
>>> http://pastebin.com/7hU20NNL
>>
>> Ruby solution: https://gist.github.com/1087583
>
> I acutally don't know Ruby that well, but it looks like your program
> recognizes "[(])" as correct although it is not, because you translate
> "[(])" to "(())" (which is indeed correct, but does not resemble the
> input correctly anymore).
Right you are. The optimization breaks the logic. Good catch!
Kind regards
robert
------------------------------
Date: Sun, 17 Jul 2011 18:54:59 +0200
From: Robert Klemme <shortcutter@googlemail.com>
Subject: Re: a little parsing challenge =?UTF-8?B?4pi6?=
Message-Id: <98gif3Fci0U1@mid.individual.net>
On 07/17/2011 06:01 PM, Robert Klemme wrote:
> On 07/17/2011 03:55 PM, mhenn wrote:
>> Am 17.07.2011 15:20, schrieb Robert Klemme:
>>> On 07/17/2011 11:48 AM, Raymond Hettinger wrote:
>>>> On Jul 17, 12:47 am, Xah Lee<xah...@gmail.com> wrote:
>>>>> i hope you'll participate. Just post solution here. Thanks.
>>>>
>>>> http://pastebin.com/7hU20NNL
>>>
>>> Ruby solution: https://gist.github.com/1087583
>>
>> I acutally don't know Ruby that well, but it looks like your program
>> recognizes "[(])" as correct although it is not, because you translate
>> "[(])" to "(())" (which is indeed correct, but does not resemble the
>> input correctly anymore).
>
> Right you are. The optimization breaks the logic. Good catch!
Turns out with a little possessiveness I can fix my original approach
which has the added benefit of not needing three passes through the file
(the two #tr's are obsolete now).
https://gist.github.com/1087583
Cheers
robert
------------------------------
Date: Sun, 17 Jul 2011 17:49:11 +0200
From: Thomas Boell <tboell@domain.invalid>
Subject: Re: a little parsing challenge =?UTF-8?Q?=E2=98=BA?=
Message-Id: <20110717174911.6f00792f@arcadia>
On Sun, 17 Jul 2011 02:48:42 -0700 (PDT)
Raymond Hettinger <python@rcn.com> wrote:
> On Jul 17, 12:47=C2=A0am, Xah Lee <xah...@gmail.com> wrote:
> > i hope you'll participate. Just post solution here. Thanks.
>=20
> http://pastebin.com/7hU20NNL
I'm new to Python. I think I'd have done it in a similar way (in any
language). Your use of openers/closers looks nice though. In the
initialization of openers, I guess you implicitly create a kind of
hash, right? Then the 'in' operator checks for the keys. That is elegant
because you have the openers and closers right next to each other, not
in separate lists.
But why do you enumerate with start=3D1? Shouldn't you start with index 0?
------------------------------
Date: Sat, 16 Jul 2011 23:19:24 +0100
From: Henry Law <news@lawshouse.org>
Subject: Re: Cpan problem XML::LibXML with Ubuntu
Message-Id: <8d-dne5b6J7yk7_TnZ2dnUVZ7sudnZ2d@giganews.com>
On 16/07/11 20:01, goldtech wrote:
> Hi,
>
> Could some one tell me the problem - I am trying to use cpan to
> install XML::LibXML. I am using Ubuntu 11.04. Here's what i get.
I don't know what you've done wrong but in Ubuntu I always find it
better to install Perl modules from the Ubuntu repositories.
Try "sudo apt-get install libxml-libxml-perl"
--
Henry Law Manchester, England
------------------------------
Date: Mon, 18 Jul 2011 09:04:47 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Cpan problem XML::LibXML with Ubuntu
Message-Id: <180720110904478281%jimsgibson@gmail.com>
In article
<70bbe2ec-cc70-4d9c-b3df-808eff66b26e@28g2000pry.googlegroups.com>,
goldtech <goldtech@worldpost.com> wrote:
> Hi,
>
> Could some one tell me the problem - I am trying to use cpan to
> install XML::LibXML. I am using Ubuntu 11.04. Here's what i get.
> Thank you:
>
> $ sudo cpan XML::LibXML
> [sudo] password for g566:
> CPAN: Storable loaded ok (v2.20)
> Going to read '/home/giga1/.cpan/Metadata'
> Database was generated on Sat, 16 Jul 2011 17:27:09 GMT
> Running install for module 'XML::LibXML'
[snip]
> CPAN.pm: Going to build S/SH/SHLOMIF/XML-LibXML-1.81.tar.gz
>
> enable native perl UTF8
> running xml2-config...untested
> Note: libxml2 2.7.8 was not tested with this XML::LibXML version.
> looking for -lxml2... no
> looking for -llibxml2... no
> libxml2, zlib, and/or the Math library (-lm) have not been found.
The above lines are a pretty good indication of what is wrong: either
libxml2, zlib, and/or the Math library (libm) have not been found on
your system.
> Try setting LIBS and INC values on the command line
> Or get libxml2 from
> http://xmlsoft.org/
Have you followed the suggestion given here?
> If you install via RPMs, make sure you also install the -devel
> RPMs, as this is where the headers (.h files) are.
Or here?
>
> Also, you may try to run perl Makefile.PL with the DEBUG=1 parameter
> to see the exact reason why the detection of libxml2 installation
> failed or why Makefile.PL was not able to compile a test program.
Or here?
> No 'Makefile' created SHLOMIF/XML-LibXML-1.81.tar.gz
> /usr/bin/perl Makefile.PL INSTALLDIRS=site -- NOT OK
> Running make test
> Make had some problems, won't test
> Running make install
> Make had some problems, won't install
> $
Do what was suggested by the installation process and let us know what
happened.
--
Jim Gibson
------------------------------
Date: Mon, 18 Jul 2011 02:08:40 -0500
From: "E.D.G." <edgrsprj@ix.netcom.com>
Subject: Re: Perl Multitasking Question
Message-Id: <TLidnZRkCrptRr7TnZ2dnUVZ_qadnZ2d@earthlink.com>
"RedGrittyBrick" <RedGrittyBrick@spamweary.invalid> wrote in message
news:4e1ec74d$0$2487$db0fefd9@news.zen.co.uk...
> See `perldoc -f fork` and `perldoc perlthrtut`
> Maybe this sort of article will be of interest:
> http://t-a-w.blogspot.com/2006/10/why-perl-is-great-language-for.html
Thanks for the information. It took me several days to get some time free
to respond to your note.
fork(); looks fairly simple. It apparently creates two identical versions
of the running .pl program. That would work for some of my applications.
However, the new and old programs do not share data from what I can see. So
that would have to be done through files or pipes etc.
use threads;
use threads::shared;
It looks like placing both of those commands at the start of the program
should get the job done. However, I have several questions regarding the
right code to use with them. I did check the URL you mentioned. But my
proposed application is nowhere near that complex.
The following is a highly simplified example of what I am trying to do. And
if anyone can volunteer some code that will work then that would be
appreciated. The new code should not be too complex. The program that it
will go into will not be running the International Space Station.
At various points the program needs to look ahead in time and tell files to
load into arrays so that their data are already in RAM memory when they are
needed. Some of those files can take as long as 10 or 20 seconds to load
and then have their data organized into different arrays. So if that can be
done before the data are needed it can keep the main program from having to
wait for that step to get completed.
Questions:
1. What code should be added to tell the program that the @filearray needs
to be shared
2. What code should be added to tell the program to run the loadfile()
subroutine (or whatever) as a separate thread
use threads;
use threads::shared;
#program code that would tell the program that @filearray needs to be shared
#(some main program code that is running before the new worker thread is
created)
#the following would be some type of code that would start the new worker
threat running
sub loadfile();
#(some main program code that runs while the new worker thread is loading
the file)
print $filearray[3], ā\nā;
sleep 10;
exit;
# this is an example of the code for loading the file into an array
sub loadfile{open filein, ā< c:\working\datafile.dat>ā;
@filearray = <filein>;
close filein;
};
------------------------------
Date: Mon, 18 Jul 2011 13:38:25 -0400
From: Ralph Malph <ralph@happydays.com>
Subject: Re: Perl Multitasking Question
Message-Id: <ac682$4e246f9d$ce534406$2510@news.eurofeeds.com>
Well, the "classic" solution to this is to used shared memory.
Since you are on Windows of course you can't use a real SysV IPC type
solution(i.e. IPC::Shareable) but you can use this
http://search.cpan.org/~roger/Win32-MMF-0.09e/MMF.pm
Which will do the trick. You need to read some docs but I would
say that this is not at all "impossibly complicated". :)
> 2. Is it possible to have multiple separately running Perl programs
> share the same data arrays (without using Perl or Windows code that is
> impossibly complicated)?
------------------------------
Date: Mon, 18 Jul 2011 10:00:19 +0000 (UTC)
From: "Dave Saville" <dave@invalid.invalid>
Subject: TZ problem
Message-Id: <fV45K0OBJxbE-pn2-RQOuF0Qchzid@localhost>
I have a problem that has nothing to do with perl directly but I can't
find a solution.
On OS/2 the standard TZ environmental is of the form:
GMT0BST,3,-1,0,3600,10,-1,0,7200,3600
Now if Apache sees that it freaks and thinks everything is GMT so
right now the logs would be one hour out. I discovered that if one
uses the POSIX form of TZ:
GMT0BST,M3.5.0/2,M10.5.0/3
Then setting that in the startup script for Apache almost gets it
right in that the time is correct but the timezone offset is not. This
might be Apache code, it has a *huge* amount of code dealing with time
stamps, or it might be my LIBC library.
However, running with the POSIX TZ then screws up perl CGI scripts (I
don't use mod_perl BTW). I am wary of resetting $ENV{TZ} in case it
affects Apache so what I think I need to do to work around the problem
is check for a POSIX TZ format and figure out for myself if DST
applies. I need to get it correct as I am generating email DATE:
headers. Before I try very hard is there any module that might assist?
I could not find one.
TIA
--
Regards
Dave Saville
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 V11 Issue 3446
***************************************