[30403] in Perl-Users-Digest
Perl-Users Digest, Issue: 1646 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 16 21:09:47 2008
Date: Mon, 16 Jun 2008 18:09:14 -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, 16 Jun 2008 Volume: 11 Number: 1646
Today's topics:
Re: Checking if an object inherits from class T <koszalekopalek@interia.pl>
Re: Expat / XML::Parser / _crypt_struct <benkasminbullock@gmail.com>
Re: FAQ 5.38 How do I select a random line from a file? xhoster@gmail.com
Re: FAQ 5.38 How do I select a random line from a file? <hjp-usenet2@hjp.at>
htmldoc...funny characters not going away <stpra123@gmail.com>
Re: Is there an include for perl? <jurgenex@hotmail.com>
Re: Is there an include for perl? <simon.chao@fmr.com>
Re: Is there an include for perl? <ben@morrow.me.uk>
Re: Is there an include for perl? <hjp-usenet2@hjp.at>
Re: Is there an include for perl? <hansmu@xs4all.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 16 Jun 2008 11:52:01 -0700 (PDT)
From: Koszalek Opalek <koszalekopalek@interia.pl>
Subject: Re: Checking if an object inherits from class T
Message-Id: <46fe7265-f03a-466b-90c2-ea77ec12a8c7@p25g2000hsf.googlegroups.com>
On Jun 15, 3:29 pm, brian d foy <brian.d....@gmail.com> wrote:
> In article <4853c7d5$0$6554$9b4e6...@newsspool3.arcor-online.net>,
>
> actaully, you want to do
>
> if( eval { $obj->isa("T") } )
>
> Call isa() directly on the object, and don't care too much about what
> is actaully in $obj. If it's not an object, you just get back false,
> which is still the right nswer to the question. :)
The only thing is that it is approximately 4x slower on my
simple benchmark compared to just checking the ref, i.e.
if( ref $obj eq 'T' )
But that's the way it has to stay.
K.
------------------------------
Date: Mon, 16 Jun 2008 22:29:45 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: Expat / XML::Parser / _crypt_struct
Message-Id: <g36pgp$pui$1@ml.accsnet.ne.jp>
On Mon, 16 Jun 2008 07:43:47 -0700, sbk wrote:
> the relevant section (around line 612) from 'reentr.h' looks like
> this:
>
> #ifdef HAS_CRYPT_R
> #if CRYPT_R_PROTO == REENTRANT_PROTO_B_CCD
> CRYPTD* _crypt_data;
> #else
> struct crypt_data _crypt_struct;
> #endif
> #endif /* HAS_CRYPT_R */
>
>
> so, presumably, the data type "_crypt_struct" hasn't been defined
>
> ==> where should this be defined?
I dunno, but if I had that problem the first thing I'd try is
#undef HAS_CRYPT_R
to just skip the whole thing, and see if I could get it to compile
without the crypt thing. If you need the crypt thing, then you'll have to
"grep" through the C header files for _crypt_struct until you find it.
------------------------------
Date: 16 Jun 2008 18:17:24 GMT
From: xhoster@gmail.com
Subject: Re: FAQ 5.38 How do I select a random line from a file?
Message-Id: <20080616141725.548$gZ@newsreader.com>
"Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
> On 2008-06-09 20:00, xhoster@gmail.com <xhoster@gmail.com> wrote:
> > Yep, and this is the algorithm that the FAQ gives. But some people are
> > not happy with it. So you have the progression:
> >
> > 1) naive: read the file once to count the lines, and again to pick
> > a random line out of it. You need to read the file, on average, 1.5
> > times.
>
> Nope. 1 + l_1/l_f times, where l_1 is the length of the line you are
> going to read and l_f is the length of the file.
That isn't very naive. I suppose you accomplish this by storing
the "tell" for each start of line? That also might run into memory
problems if the file is quite large.
>
> > 3) If you are willing to compromise by preprocessing the file--either
> > into something else or building an auxiliary structure--or having
> > longer lines be more likely to be chosen than shorter lines, then of
> > course you can do better than reading the entire file even once (per
> > execution). I think that is outside the scope of the FAQ, but it is
> > what people decided to discuss.
>
> I think that's a more realistic approach. How often do you need to
> choose exactly one random line from a file which you've never seen
> before and will never see again?
I don't think I've ever needed to pick exactly one random line from a file
too large to fit in memory in the first place! But extrapolating from
what experience I do have with vaguely similar situations, I think that
often one does not want to take on the responsibility of keeping track of
what files one has seen before or will see in the future, so it is often
worth trading some performance to avoid having to keep track of such stuff.
Or not.
> When you need to get two random lines
> from the file building some kind of index is already faster.
The reservoir method can readily be extended to get two random lines.
I assume the reference given in the FAQ covers that situation.
The problem with FAQs is that often the correct answer for a specific
situation in which someone asks a questions is "You are asking the wrong
question", but there is only so far you can do down that road before
all the FAQs become either a dissertation, or merely an injunction to go
read Knuth, and at that point they are probably useless for their intended
purpose.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Mon, 16 Jun 2008 23:29:57 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 5.38 How do I select a random line from a file?
Message-Id: <slrng5dmql.n03.hjp-usenet2@hrunkner.hjp.at>
On 2008-06-16 18:17, xhoster@gmail.com <xhoster@gmail.com> wrote:
> "Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
>> On 2008-06-09 20:00, xhoster@gmail.com <xhoster@gmail.com> wrote:
>> > Yep, and this is the algorithm that the FAQ gives. But some people are
>> > not happy with it. So you have the progression:
>> >
>> > 1) naive: read the file once to count the lines, and again to pick
>> > a random line out of it. You need to read the file, on average, 1.5
>> > times.
>>
>> Nope. 1 + l_1/l_f times, where l_1 is the length of the line you are
>> going to read and l_f is the length of the file.
>
> That isn't very naive.
Maybe I'm not prone to naive solutions ;-).
> I suppose you accomplish this by storing the "tell" for each start of
> line?
Yes. If I have to read the file I might as well take advantage of it.
> That also might run into memory problems if the file is quite large.
There's always the disk. (Well, not always, but ...)
>> > 3) If you are willing to compromise by preprocessing the file--either
>> > into something else or building an auxiliary structure--or having
>> > longer lines be more likely to be chosen than shorter lines, then of
>> > course you can do better than reading the entire file even once (per
>> > execution). I think that is outside the scope of the FAQ, but it is
>> > what people decided to discuss.
>>
>> I think that's a more realistic approach. How often do you need to
>> choose exactly one random line from a file which you've never seen
>> before and will never see again?
>
> I don't think I've ever needed to pick exactly one random line from a file
> too large to fit in memory in the first place!
I did - as I wrote earlier in these thread, I wrote a fortune program
20+ years ago. And while the file would have fit in memory on the
machine I first developed it on, sticking to an index made porting much
easier. (Also, I probably wasn't firm enough in using C memory
management at that time, IIRC. At least not on an 8086 machine. It was
probably one of the first C programs I wrote)
> But extrapolating from what experience I do have with vaguely similar
> situations, I think that often one does not want to take on the
> responsibility of keeping track of what files one has seen before or
> will see in the future, so it is often worth trading some performance
> to avoid having to keep track of such stuff.
Yes. But that's the "quick and dirty one-time hack" situation. Any
solution will do as long as it's quick to implement. If you know Knuth's
algorithm, fine. If you have to get TAOCP from the attic, it probably
isn't worth the bother.
>> When you need to get two random lines from the file building some
>> kind of index is already faster.
>
> The reservoir method can readily be extended to get two random lines.
If you need exactly two (or three or any fixed number), yes. But it
doesn't work if you don't know the number in advance, or if the lines
are needed by different processes.
hp
------------------------------
Date: Mon, 16 Jun 2008 16:23:58 -0700 (PDT)
From: hotkitty <stpra123@gmail.com>
Subject: htmldoc...funny characters not going away
Message-Id: <39e91831-9460-4b0a-b5db-2e4db4b87510@x35g2000hsb.googlegroups.com>
Hi,
Am using htmldoc to turn webpages into pdf files. When using the gui
application the pdf file turns out great. However, when using perl to
call the program the pdf apostraphes, quotations get turned into
symbols (apostraphes get turned into a-hat). Obviously its an encoding
issue but I've used various methods like setting the character set
like cpan says, uri::escape and even tried substituting the character
for the symbol (=~ s/a-hat/'/g) to no avail. Any suggestions?
------------------------------
Date: Mon, 16 Jun 2008 18:12:54 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Is there an include for perl?
Message-Id: <a3bd54d75lumcrj8326j5qelj22i2al2fm@4ax.com>
Bill H <bill@ts1000.us> wrote:
>On Jun 16, 1:19 pm, Jürgen Exner <jurge...@hotmail.com> wrote:
>> Bill H <b...@ts1000.us> wrote:
>> >I am looking for an include for perl. I know about require, use etc
>> >and use them, but I have a program that is getting large and would
>> >like to put some of the code into their own files and just use a
>> >include "filename" where the code I pulled belongs and have nothing
>> >else done to that included code other than it being inserted when the
>> >program is run.
>>
>> Are you looking for do()?
>
>Hi Jurgen. I looked at do() and it didn't seem to fit what I want.
Well, I suppose you can always run your Perl program through cpp first
and feed the result to perl.
jue
------------------------------
Date: Mon, 16 Jun 2008 11:18:48 -0700 (PDT)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: Is there an include for perl?
Message-Id: <b6886843-e3ec-4594-bdec-ba75fd7831e5@8g2000hse.googlegroups.com>
On Jun 16, 2:07=A0pm, Bill H <b...@ts1000.us> wrote:
> On Jun 16, 1:19=A0pm, J=FCrgen Exner <jurge...@hotmail.com> wrote:
>
> > Bill H <b...@ts1000.us> wrote:
> > >I am looking for an include for perl. I know about require, use etc
> > >and use them, but I have a program that is getting large and would
> > >like to put some of the code into their own files and just use a
> > >include "filename" where the code I pulled belongs and have nothing
> > >else done to that included code other than it being inserted when the
> > >program is run.
>
> > Are you looking for do()?
>
> > jue
>
> Hi Jurgen. I looked at do() and it didn't seem to fit what I want.
>
How does do() not fit what you want? It seems to exactly fit your
requirements to me...
------------------------------
Date: Mon, 16 Jun 2008 20:48:23 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Is there an include for perl?
Message-Id: <7lsii5-tf91.ln1@osiris.mauzo.dyndns.org>
Quoth Bill H <bill@ts1000.us>:
> I am looking for an include for perl. I know about require, use etc
> and use them, but I have a program that is getting large and would
> like to put some of the code into their own files and just use a
> include "filename" where the code I pulled belongs and have nothing
> else done to that included code other than it being inserted when the
> program is run. As an example:
>
>
> main program:
>
> line 1
> line 2
> include "other program"
> line 3
> line 4
>
> other program
> line 2a
> line 2b
> line 2c
>
> when perl runs main program it sees it as
>
> line 1
> line 2
> line 2a
> line 2b
> line 2c
> line 3
> line 4
>
> I know you can do this with require but I have issues with variables
> being set in one require not being available in another
Use require and declare all variables that you want to be shared between
files with 'our' instead of 'my'.
Generally speaking this is a bad idea. It is much better to split the
code into logical sections, with well-defined means of communication
between them. Then you put each section into a proper module.
Ben
--
The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching.
Assyrian stone tablet, c.2800 BC ben@morrow.me.uk
------------------------------
Date: Mon, 16 Jun 2008 23:36:54 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Is there an include for perl?
Message-Id: <slrng5dn7o.n03.hjp-usenet2@hrunkner.hjp.at>
On 2008-06-16 18:18, nolo contendere <simon.chao@fmr.com> wrote:
> On Jun 16, 2:07 pm, Bill H <b...@ts1000.us> wrote:
>> On Jun 16, 1:19 pm, Jürgen Exner <jurge...@hotmail.com> wrote:
>>
>> > Bill H <b...@ts1000.us> wrote:
>> > >I am looking for an include for perl. I know about require, use etc
>> > >and use them, but I have a program that is getting large and would
>> > >like to put some of the code into their own files and just use a
>> > >include "filename" where the code I pulled belongs and have nothing
>> > >else done to that included code other than it being inserted when the
>> > >program is run.
>>
>> > Are you looking for do()?
More likely for eval.
>> Hi Jurgen. I looked at do() and it didn't seem to fit what I want.
>
> How does do() not fit what you want?
Probably in exactly the same way as require and use don't fit, as the
visibility of variables is the same in all three cases.
But that's a feature, not a bug. If a program is getting too large, you
need to separate it so that you can understand the parts individually
(the times when you had to split your files because otherwise the editor
or compiler would choke on them are hopefully long gone). Otherwise it
becomes harder to understand, not easier.
hp
------------------------------
Date: Tue, 17 Jun 2008 01:21:51 +0200
From: Hans Mulder <hansmu@xs4all.nl>
Subject: Re: Is there an include for perl?
Message-Id: <4856f59d$0$14349$e4fe514c@news.xs4all.nl>
Jürgen Exner wrote:
> Bill H <bill@ts1000.us> wrote:
>> On Jun 16, 1:19 pm, Jürgen Exner <jurge...@hotmail.com> wrote:
>>> Bill H <b...@ts1000.us> wrote:
>>>> I am looking for an include for perl. I know about require, use etc
>>>> and use them, but I have a program that is getting large and would
>>>> like to put some of the code into their own files and just use a
>>>> include "filename" where the code I pulled belongs and have nothing
>>>> else done to that included code other than it being inserted when the
>>>> program is run.
>>> Are you looking for do()?
>> Hi Jurgen. I looked at do() and it didn't seem to fit what I want.
>
> Well, I suppose you can always run your Perl program through cpp first
> and feed the result to perl.
If you want to use the cpp, consider perl's -P option, which does
exactly that.
Incidentally, the section on -P in perlrun explains why this is a
bad idea.
Hope this helps,
-- HansM
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 1646
***************************************