[30795] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2040 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 8 00:09:47 2008

Date: Sun, 7 Dec 2008 21:09:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 7 Dec 2008     Volume: 11 Number: 2040

Today's topics:
        Cambodia TEFL - Gap Year, Travel & Study, Paid Teaching <jobs.teaching.english.asia@gmail.com>
    Re: herding ones and zeroes into bytes sln@netherlands.com
    Re: how detect english subject and predicate in a sente <hjp-usenet2@hjp.at>
    Re: how detect english subject and predicate in a sente <nospam-abuse@ilyaz.org>
        how to use stack combining with if? <ela@yantai.org>
    Re: how to use stack combining with if? <ela@yantai.org>
    Re: how to use stack combining with if? <jurgenex@hotmail.com>
    Re: Mathematica 7 compares to other languages <jon@ffconsultancy.com>
    Re: Mathematica 7 compares to other languages <xahlee@gmail.com>
    Re: perl segfault - how to troubleshoot <tim@burlyhost.com>
        Query problem expressed in PHP <usenet@larseighner.com>
    Re: Query problem expressed in PHP <usenet@larseighner.com>
        wget/sftp- style progress bar <simonsharry@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 7 Dec 2008 18:56:00 -0800 (PST)
From: Jobs Teaching English in Asia <jobs.teaching.english.asia@gmail.com>
Subject: Cambodia TEFL - Gap Year, Travel & Study, Paid Teaching Job -  http://www.cambodiatefl.com
Message-Id: <a00de31c-3057-4f69-93fb-1821ede49118@o4g2000pra.googlegroups.com>

Cambodia TEFL - Gap Year, Travel & Study, Paid Teaching Job


http://www.cambodiatefl.com


------------------------------

Date: Sun, 07 Dec 2008 21:03:36 GMT
From: sln@netherlands.com
Subject: Re: herding ones and zeroes into bytes
Message-Id: <vaeoj41rjr5ul81f8jn35g69qrir8q49lk@4ax.com>

On Sat, 6 Dec 2008 20:35:46 -0700, George <george@example.invalid> wrote:

>
>
>I continue to try to implement a black word/white word encoding similar to 
>the treatment given in chp. 18 of _unleashed_.
>
>#include <stdio.h>
>#include <stdlib.h>
>
>#define PATH "george.txt"
>#define NUMBER 100
>#define MAXFMTLEN 2000
>
>int main(void)
>{
>  FILE *fp;
>  char pattern[MAXFMTLEN];
>  char lbin[NUMBER];
>  char line[MAXFMTLEN];
>
>  if ((fp = fopen(PATH, "r")) == NULL ) {
>    fprintf(stderr, "can't open file\n");
>    exit(1);
>  }
>
>  sprintf(pattern, "%%*s %%%ds", NUMBER-1);
>
>
>   
> while(fgets(line, MAXFMTLEN, fp) == line){
>    sscanf(line, pattern , lbin);
>    
>    printf("%s\n", lbin);
>  }
>  
>
>
>  fclose(fp);
>  return 0;
>}
>
>// gcc -o x.exe chad6.c
>
>output is:
>
>C:\MinGW\source>gcc -o x.exe chad6.c
>
>C:\MinGW\source>x
>0001000000000000001
>0001000000000000001
>10000011001000000000000001
>10000011001000000000000001
>10000011001000000000000001
>10000011001000000000000001
>10000011001000000000000001
>10000011001000000000000001
>10000011001000000000000001
>10000011001000000000000001
>100000001111100
>100000001111100
>100000001111100
>1000001110110111100000000000001
>1000001110110111100000000000001
>1000001110110111100000000000001
>1000001110110111100000000000001
>1000001110110111100000000000001
>1000001110110111100000000000001
>0001000000000000001
>
>The next step is to herd these into bytes.  I tried to follow what Jack 
>Klein does, but his encode.c is too complex for me to follow, and it's 20 
>K.  I'm able to do it in fortran and know that the file I want looks like:
>
>C:\MinGW\source>od -tx1 -Ax -v bin3.dat
>
>C:\MinGW\source>dump bin3.dat
>
>000000 0d 0a 10 00 22 00 06 0c 80 01 83 20 00 60 c8 00
>000010 18 32 00 06 0c 80 01 83 20 00 60 c8 00 18 32 00
>000020 06 03 e4 20 c8 0f 90 76 f0 00 60 ed e0 00 c1 db
>000030 c0 01 83 b7 80 03 20 6f 00 06 0e de 00 08 80 01
>000040
>
>, without the initial crlf.  I added that because encode.c to try to be 
>kosher with the usage (it would make my code garbage).  Maybe, hints of of 
>why I don't succeed follow:
>
>C:\MinGW\source>gcc encode1.c -o prog.exe
>
>C:\MinGW\source>prog
>usage: encode binary-input-file, t4-output-file
>
>C:\MinGW\source>prog bin3.dat out.t4
>encoded 0 rows from bin3.dat to out.t4
>
>
>It's kind of a rambling post; let me restate my intent.  I'd like to herd 
>the ones and zeroes in  char lbin[NUMBER] into bytes. I have 8 bit bytes, 
>but there isn't any reason not to write it portably.  The final byte is to 
>be padded with zeroes to the left.  The output I believe to be correct is 
>the last 62 values in the hex dump.
>
>Thanks for your comment.

Hey, just a reminder this is not a C group, although this is easy to
do in Perl. I have no idea what your trying to accomplish but
here is a free extension course:

char *Bits =
"0001000000000000001\
0001000000000000001\
10000011001000000000000001\
10000011001000000000000001\
10000011001000000000000001\
10000011001000000000000001\
10000011001000000000000001\
10000011001000000000000001\
10000011001000000000000001\
10000011001000000000000001\
100000001111100\
100000001111100\
100000001111100\
1000001110110111100000000000001\
1000001110110111100000000000001\
1000001110110111100000000000001\
1000001110110111100000000000001\
1000001110110111100000000000001\
1000001110110111100000000000001\
0001000000000000001";

	printf ("\nlength Bits = %d\nBits = %s", strlen(Bits), Bits);
	
	if (0)
		for (int i=0; i<strlen(Bits); i+=8)
		{
			char sbyte[9] = "00000000";
			strncpy(sbyte, &Bits[i], 8);
			int byte = 0;
			for (int d=7; d>=0; d--)
				byte += ((sbyte[d]-'0')<<(7-d));
			printf ("%02x   %s\n", byte, sbyte);
		}
	// or simply:
	for (int i=0; i<strlen(Bits); i+=8)
	{
		int byte = 0;
		for (int d=7; d>=0; d--)
			byte += ((Bits[i+d]-'0')<<(7-d));
		printf ("%02x\n", byte);
	}

sln



------------------------------

Date: Sun, 7 Dec 2008 15:37:10 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: how detect english subject and predicate in a sentence
Message-Id: <slrngjnnsn.he5.hjp-usenet2@hrunkner.hjp.at>

On 2008-12-06 22:25, Charlton Wilbur <cwilbur@chromatico.net> wrote:
>>>>>> "PJH" == Peter J Holzer <hjp-usenet2@hjp.at> writes:
>
>     >> Actually, the sentence can be read *correctly* in two
>     >> incompatible ways.  You can read "Fruit flies" as the subject,
>     >> and "like a banana" as the predicate, or "Fruit" as the subject,
>     >> and "flies like a banana" as the predicate.  Both readings are
>     >> correct.
>
>    PJH> Only syntactically. 
>
> You're trying to make a distinction between the reading of the sentence
> conveying information (in which sense both readings are correct) and the
> reading of the sentence conveying factually true information.
>
> This is a level removed from correctly parsing the sentence.

No, it is necessary for correctly parsing the sentence. Syntactically
both sentences can be parsed both ways:

1 ((time flies) (like) (an arrow))
2 ((fruit flies) (like) (a banana))
3 ((time) (flies) (like an arrow))
4 ((fruit) (flies) (like a banana))

All four parse trees are syntactically correct and all four convey
information. It is only semantics which makes us prefer 3 over 1 and 2
over 4. 

> For instance, given the sentence "Tokyo is the capital of
> Massachusetts," the correct reading of the sentence is factually wrong.
> This does not make it grammatically incorrect or even grammatically
> ambiguous.

As you say, this sentence isn't grammatically ambiguous. There is only
one possible subject (Tokyo) one possible predicate (is) and one
possible object (the capital of Massachusetts). You don't have to
decide between different parse trees using semantics.

	hp


------------------------------

Date: Sun, 7 Dec 2008 21:05:58 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: how detect english subject and predicate in a sentence
Message-Id: <ghhdrm$1k8n$1@agate.berkeley.edu>

[A complimentary Cc of this posting was NOT [per weedlist] sent to
Peter J. Holzer
<hjp-usenet2@hjp.at>], who wrote in article <slrngjnnsn.he5.hjp-usenet2@hrunkner.hjp.at>:
> > For instance, given the sentence "Tokyo is the capital of
> > Massachusetts," the correct reading of the sentence is factually wrong.
> > This does not make it grammatically incorrect or even grammatically
> > ambiguous.
> 
> As you say, this sentence isn't grammatically ambiguous. There is only
> one possible subject (Tokyo) one possible predicate (is) and one
> possible object (the capital of Massachusetts).

???  `Tokio' is an adjective for subject `is' (plural of `i' denoting
a sound or a letter); the rest is clarification (do not remember the
correct grammatical category).

  Who knocks at my doors?
  We the rulers of universe.

Ilya

P.S.  In the `rulers' example there is a grammatical correlation of
      plurality of `we' and `rulers' but obviously it is not always
      present.  (Can't give an example right now, though...)


------------------------------

Date: Mon, 8 Dec 2008 03:37:31 +0800
From: "ela" <ela@yantai.org>
Subject: how to use stack combining with if?
Message-Id: <ghh8lr$r3p$1@ijustice.itsc.cuhk.edu.hk>

I have a set of numbers representing student IDs and these students need 
special attention to their grades.

      220048 311611 519804 797736 909164
      a b a c e


in fact the grade file is in a format like this:

1    a
2    a
3    c
4    b
5    a
6    b
7    ...
4000000    a

I would like to use the student IDs to obtain their corresponding grades, 
stack seems to be a solution but I don't know how to combine it elegantly 
with "if". Does anybody have a suggestion? Thanks. 




------------------------------

Date: Mon, 8 Dec 2008 04:35:22 +0800
From: "ela" <ela@yantai.org>
Subject: Re: how to use stack combining with if?
Message-Id: <ghhc2b$t0r$1@ijustice.itsc.cuhk.edu.hk>


"ela" <ela@yantai.org> wrote in message 
news:ghh8lr$r3p$1@ijustice.itsc.cuhk.edu.hk...
>I have a set of numbers representing student IDs and these students need 
>special attention to their grades.
>
>      220048 311611 519804 797736 909164
>      a b a c e
>
>
> in fact the grade file is in a format like this:
>
> 1    a
> 2    a
> 3    c
> 4    b
> 5    a
> 6    b
> 7    ...
> 4000000    a
>

Furthermore, we have to look for whether any student in particular classes 
not taking the exam, e.g.

class A:             578732 578886

class B:             581965 582162

class C:             960063 960325

 ...

So again as I have the file
578732 578886
581965 582162
 ...

how can i check the presence of exam, giving that the file this time is not 
with numbers monotonically increasing? 




------------------------------

Date: Sun, 07 Dec 2008 14:03:32 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: how to use stack combining with if?
Message-Id: <aihoj4tetmdi35sm1heml0jj4iloe6t9sf@4ax.com>

"ela" <ela@yantai.org> wrote:
>
>"ela" <ela@yantai.org> wrote in message 
>news:ghh8lr$r3p$1@ijustice.itsc.cuhk.edu.hk...
>>I have a set of numbers representing student IDs and these students need 
>>special attention to their grades.
>>
>>      220048 311611 519804 797736 909164
>>      a b a c e
>>
>>
>> in fact the grade file is in a format like this:
>>
>> 1    a
>> 2    a
>> 3    c
>> 4    b
>> 5    a
>> 6    b
>> 7    ...
>> 4000000    a
>>
>
>Furthermore, we have to look for whether any student in particular classes 
>not taking the exam, e.g.
>
>class A:             578732 578886
>
>class B:             581965 582162
>
>class C:             960063 960325
>
>...
>
>So again as I have the file
>578732 578886
>581965 582162
>...
>
>how can i check the presence of exam, giving that the file this time is not 
>with numbers monotonically increasing? 

Your descriptions are not clear to me at all, but the general approach
to this kind of problem is to read the shorter or less organized data
into memory, creating a data structure that is is well organized and
targeted to make the main task easier. In your case, where you want to
check if a given number appears in the "special attention list" or the
"didn't take exam" list, a hash seems to be quite convenient.
And then just loop through the larger list one by one checking if the
current element occurs in either of your predetermined check lists.

If you get even more special lists, then the opposite approach might be
more useful: reading the whole student list into memory once and then
walking through your special lists one by one.

I have no idea what you mean by "stack combining with if". Those two
have about nothing in common at all.
jue


------------------------------

Date: Sun, 07 Dec 2008 17:39:30 +0000
From: Jon Harrop <jon@ffconsultancy.com>
Subject: Re: Mathematica 7 compares to other languages
Message-Id: <Xv6dncWkcZMllKHUnZ2dnUVZ8oadnZ2d@posted.plusnet>

Xah Lee wrote:
> I didn't realize until after a hour, that if Jon simply give numerical
> arguments to Main and Create, the result timing by a factor of 0.3 of
> original. What a incredible sloppiness! and he intended this to show
> Mathematica speed with this code?
>
> The Main[] function calls Create. The create has 3 parameters: level,
> c, and r. The level is a integer for the recursive level of
> raytracing . The c is a vector for sphere center i presume. The r is
> radius of the sphere. His input has c and r as integers, and this in
> Mathematica means computation with exact arithmetics (and automatic
> kicks into infinite precision if necessary). Changing c and r to float
> immediately reduced the timing to 0.3 of original.

That is only true if you solve a completely different and vastly simpler
problem, which I see you have (see below).

> The RaySphere function contain codes that does symbolic computation by
> calling Im, which is the imaginary part of a complex number!! and if
> so, it returns the symbol Infinity! The possible result of Infinity is
> significant because it is used in Intersect to do a numerical
> comparison in a If statement. So, here in these deep loops,
> Mathematica's symbolic computation is used for numerical purposes!

Infinity is a floating point number.

> So, first optimization at the superficial code form level is to get
> rid of this symbolic computation.

That does not speed up the original computation.

> Instead of checking whethere his “disc = Sqrt[b^2 - v.v + r^2]” has
> imaginary part, one simply check whether the argument to sqrt is
> negative.

That does not speed up the original computation.

> after getting rid of the symbolic computation, i made the RaySphere
> function to be a Compiled function.

That should improve performance but the Mathematica remains well over five
orders of magnitude slower than OCaml, Haskell, Scheme, C, C++, Fortran,
Java and even Lisp!

> Besides the above basic things, there are several aspects that his
> code can improve in speed. For example, he used pattern matching to do
> core loops.
> e.g. Intersect[o_, d_][{lambda_, n_}, Bound[c_, r_, s_]]
> 
> any Mathematica expert knows that this is something you don't want to
> do if it is used in a core loop. Instead of pattern matching, one can
> change the form to Function and it'll speed up.

Your code does not implement this change.

> Also, he used “Block”, which is designed for local variables and the
> scope is dynamic scope. However the local vars used in this are local
> constants. A proper code would use “With” instead. (in lisp, this is
> various let, let*. Lispers here can imagine how lousy the code is
> now.)

Earlier, you said that "Module" should be used. Now you say "With". Which is
it and why?

Your code does not implement this change either.

> Here's a improved code. The timing of this code is about 0.2 of the
> original.
> ...
> Timing[Export["image.pgm",Graphics@Raster@Main[2,100,4.]]]

You have only observed a speedup because you have drastically simplified the
scene being rendered. Specifically, the scene I gave contained over 80,000
spheres but you are benchmarking with only 5 spheres and half of the image
is blank!

Using nine levels of spheres as I requested originally, your version is not
measurably faster at all.

Perhaps you should give a refund?

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?u


------------------------------

Date: Sun, 7 Dec 2008 14:53:49 -0800 (PST)
From: Xah Lee <xahlee@gmail.com>
Subject: Re: Mathematica 7 compares to other languages
Message-Id: <48b8b065-6193-454c-a548-3117449f8a55@40g2000prx.googlegroups.com>


For those interested in this Mathematica problem, i've now cleaned up
the essay with additional comments here:

=E2=80=A2 A Mathematica Optimization Problem
  http://xahlee.org/UnixResource_dir/writ/Mathematica_optimization.html

The result and speed up of my code can be verified by anyone who has
Mathematica.

Here's some additional notes i added to the above that is not
previously posted.

-------------------------

Advice For Mathematica Optimization

Here's some advice for mathematica optimization, roughly from most
important to less important:

    * Any experienced programer knows, that optimization at the
algorithm level is far more important than at the level of code
construction variation. So, make sure the algorithm used is good, as
opposed to doodling with your code forms. If you can optimize your
algorithm, the speed up may be a order of magnitude. (for example,
various algorithm for sorting algorithms=E2=86=97 illustrates this.)

    * If you are doing numerical computation, always make sure that
your input and every intermediate step is using machine precision.
This you do by making the numbers in your input using decimal form
(e.g. use =E2=80=9C1.=E2=80=9D, =E2=80=9CN[Pi]=E2=80=9D instead of =E2=80=
=9C1=E2=80=9D, =E2=80=9CPi=E2=80=9D). Otherwise Mathematica
may use exact arithmetics.

    * For numerical computation, do not simply slap =E2=80=9CN[]=E2=80=9D i=
nto your
code. Because the intermediate computation may still be done using
exact arithmetic or symbolic computation.

    * Make sure your core loop, where your calculation is repeated and
takes most of the time spent, is compiled, by using Compile.

    * When optimizing speed, try to avoid pattern matching. If your
function is =E2=80=9Cf[x_]:=3D ...=E2=80=9D, try to change it to the form o=
f =E2=80=9Cf=3DFunction
[x,...]=E2=80=9D instead.

    * Do not use complicated patterns if not necessary. For example,
use =E2=80=9Cf[x_,y_]=E2=80=9D instead of =E2=80=9Cf[x_][y_]=E2=80=9D.

 ------------------------------

 ...

Besides the above basic things, there are several aspects that his
code can improve in speed. For example, he used rather complicated
pattern matching to do intensive numerical computation part. Namely:

Intersect[o_, d_][{lambda_, n_}, Bound[c_, r_, s_]]
Intersect[o_, d_][{lambda_, n_}, Sphere[c_, r_]]

Note that the way the parameters of Intersect defined above is a
nested form. The code would be much faster if you just change the
forms to:

Intersect[o_, d_, {lambda_, n_}, Bound[c_, r_, s_]]
Intersect[o_, d_, {lambda_, n_}, Sphere[c_, r_]]

or even just this:

Intersect[o_, d_, lambda_, n_, c_, r_, s_]
Intersect[o_, d_, lambda_, n_, c_, r_]

Also, note that the Intersect is recursive. Namely, the Intersect
calls itself. Which form is invoked depends on the pattern matching of
the parameters. However, not only that, inside one of the Intersect it
uses Fold to nest itself. So, there are 2 recursive calls going on in
Intersect. Reducing this recursion to a simple one would speed up the
code possibly by a order of magnitude.

Further, if Intersect is made to take a flat sequence of argument as
in =E2=80=9CIntersect[o_, d_, lambda_, n_, c_, r_, s_]=E2=80=9D, then patte=
rn matching
can be avoided by making it into a pure function =E2=80=9CFunction=E2=80=9D=
 . And when
it is a =E2=80=9CFunction=E2=80=9D, then Intersect or part of it may be com=
piled with
Compile. When the code is compiled, the speed should be a order of
magnitude faster.

-----------------------------

Someone keeps claiming that Mathematica code is some =E2=80=9C5 order of
magnitude slower=E2=80=9D. It is funny how the order of magnitude is
quantified. I'm not sure there's a standard interpretation other than
hyperbole.

There's a famous quote by Alan Perlis ( http://en.wikipedia.org/wiki/Alan_P=
erlis
) that goes:
=E2=80=9CA Lisp programmer knows the value of everything, but the cost of
nothing.=E2=80=9D

this quote captures the nature of lisp in comparison to most other
langs at the time the quote is written. Lisp is a functional lang, and
in functional langs, the concept of values is critical, because any
lisp program is either a function definition or expression. Function
and expression act on values and return values. The values along with
definitions determines the program behavior. =E2=80=9Cthe cost of nothing=
=E2=80=9D
captures the sense that in high level langs, esp dynamic langs like
lisp, it's easy to do something, but it is more difficult to know the
algorithmic behavior of constructs. This is in contrast to langs like
C, Pascal, or modern lang like Java, where almost anything you write
in it is =E2=80=9Cfast=E2=80=9D, simply forced by the low level nature of t=
he lang.

In a similar way, Mathematica is far more higher level than any
existing lang, counting other so-called computer algebra systems. A
simple one-liner Mathematica construct easily equates to 10 or hundred
lines of lisp, perl, python, and if you count its hundreds of
mathematical functions such as Solve, Derivative, Integrate, each line
of code is equivalent to a few thousands lines in other langs.

However, there is a catch, that applies to any higher level langs,
namely, it is extremely easy, to create a program that are very
inefficient.

This can typically be observed in student or beginner's code in lisp.
The code may produce the right output, but may be extremely
inefficient for lacking expertise with the language.

The phenomenon of creating code that are inefficient is proportional
to the highlevelness or power of the lang. In general, the higher
level of the lang, the less possible it is actually to produce a code
that is as efficient as a lower level lang. For example, the level or
power of lang can be roughly order as this:

assembly langs
C, pascal
C++, java, c#
unix shells
perl, python, ruby, php
lisp
Mathematica

the lower level the lang, the longer it consumes programer's time, but
faster the code runs. Higher level langs may or may not be crafted to
be as efficient. For example, code written in the level of langs such
as perl, python, ruby, will never run as fast as C, regardless what
expert a perler is. C code will never run as fast as assembler langs.
And if the task crafting a raytracing software, then perl, python,
ruby, lisp, Mathematica, are simply not suitable, and are not likely
to produce any code as fast as C or Java.

On the other hand, higher level langs in many applications simply
cannot be done with lower level lang for various practical reasons.
For example, you can use Mathematica to solve some physics problem in
few hours, or give Pi to gazillion digits in few seconds with just =E2=80=
=9CN
[Pi,10000000000000]=E2=80=9D. Sure, you can code a solution in lisp, perl, =
or
even C, but that means few years of man hours. Similarly, you can do
text processing in C, Java, but perl, python, ruby, php, emacs lisp,
Mathematica, can reduce your man hours to 10% or 1% of coding effort.

In the above, i left out functional langs that are roughly statically
typed and compiled, such as Haskell, OCaml, etc. I do not have
experience with these langs. I suppose they do maitain some advantage
of low level lang's speed, yet has high level constructs. Thus, for
computationally intensive tasks such as writing a raytracer, they may
compete with C, Java in speed, yet easier to write with fewer lines of
code.

personally, i've made some effort to study Haskell but never went thru
it. In my experience, i find langs that are (roughly called) strongly
typed, difficult to learn and use. (i have reading knowledge of C and
working knowledge of Java, but am never good with Java. The verbosity
in Java turns me off thoroughly.)

-----------------

as to how fast Mathematica can be in the raytracing toy code shown in
this thread, i've given sufficient demonstration that it can be speed
up significantly. Even Mathematica is not suitable for this task, but
i'm pretty sure can make the code's speed in the some level of speed
as OCaml.
(as opposed to someone's claim that it must be some 700000 times
slower or some =E2=80=9C5 orders of magnituted slower=E2=80=9D). However, t=
o do so
will take me half a day or a day of coding. Come fly $300 to my paypal
account, then we'll talk. Money back guaranteed, as i said before.

  Xah
=E2=88=91 http://xahlee.org/

=E2=98=84


------------------------------

Date: Sun, 07 Dec 2008 09:59:00 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: perl segfault - how to troubleshoot
Message-Id: <E9U_k.14035$v37.7180@newsfe01.iad>

Dr.Ruud wrote:

> Tim Greer schreef:
>> sln@netherlands.com:
> 
>> I've decided to lift my filter on you
> 
> *PLONK*
> 

Good grief, calm down about the whole thing.  Without seeing his posts,
besides the fact it makes your day more fun, is the fact you can
correct him for the sake of the OP, which I had done.
-- 
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting.  24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!


------------------------------

Date: Mon, 8 Dec 2008 03:21:15 +0000 (UTC)
From: Lars Eighner <usenet@larseighner.com>
Subject: Query problem expressed in PHP
Message-Id: <slrngjp4lg.2b0g.usenet@debranded.larseighner.com>


I have this MySQL table:

TABLE: content_path
+--------------+--------+
| node         | parent |
+--------------+--------+
| /works       | /      | 
| /EIGHNER     | /      | 
| /            | 0      | 
| /works/essay | /works | 
+--------------+--------+

The table will never be very large, so recursion seems to be the best way to
traverse this hierarchal information.  Obviously these are unix-style file
paths, but in researching this, I see the same sort of table often occurs in
product category problems.  I also note that such tables don't comply with
database normalization --- which is over my head --- but many people are
attracted by the convenience of this kind of table.

I wrote (stole[1]) this function, which works.

<?php

function tree_slash_children(){
global $line;
$numargs = func_num_args();
if($numargs >= 1){$field = func_get_arg(0);}else{$field = 'node';}
if($numargs >= 2){$table = func_get_arg(1);}else{$table = 'content_path';}
if($numargs >= 3){$parent = func_get_arg(2);}else{$parent = '0';}
if($numargs >= 4){$level = func_get_arg(3);}else{$level = 0;}
$result = mysql_query('SELECT node FROM '.$table.
                      ' WHERE parent="'.$parent.'"');
while ($row = mysql_fetch_array($result)) {
          $line = $line . str_repeat('|',$level).$row['node'];
          tree_slash_children($field, $table, $row['node'], $level+1);
                                           }

                              }

?>

Because global $line = '' before the call, the return is:

   /|/works||/works/essay|/EIGHNER



Now it occurs to me that the parent field is redundant.

If node = '/' we know there is no parent, and otherwise we know the parent
is s#/[^/]*$##.

I'd like to dispose of the parent field, but MySQL despite having a replace
function and having regex matching, does not have regex replacement.

I'd like to do something like:

function tree_slash_descend(){
global $line;
$numargs = func_num_args();
if($numargs >= 1){$field = func_get_arg(0);}else{$field = 'node';}
if($numargs >= 2){$table = func_get_arg(1);}else{$table = 'content_path';}
if($numargs >= 3){$parent = func_get_arg(2);}else{$parent = '';} //?
if($numargs >= 4){$level = func_get_arg(3);}else{$level = 0;}
$result = mysql_query('SELECT node FROM '.$table.
                      ' WHERE [****some kind of test on node *****]');
while ($row = mysql_fetch_array($result)) {
          $line = $line . str_repeat('|',$level).$row['node'];
          tree_slash_children($field, $table, $row['node'], $level+1);
                                          }

                           }

but I don't see it.

Any suggestions?


[1] based on 
<http://www.sitepoint.com/article/hierarchical-data-database/>
Storing Hierarchical Data in a Database [PHP &amp; MySQL Tutorials]
by Gijs Van Tulder

-- 
        Lars Eighner <http://larseighner.com/> usenet@larseighner.com
           Don't sweat the petty things, just pet the sweaty things.


------------------------------

Date: Mon, 8 Dec 2008 03:24:11 +0000 (UTC)
From: Lars Eighner <usenet@larseighner.com>
Subject: Re: Query problem expressed in PHP
Message-Id: <slrngjp4r1.2b0g.usenet@debranded.larseighner.com>

In our last episode, 
<slrngjp4lg.2b0g.usenet@debranded.larseighner.com>, 
the lovely and talented Lars Eighner 
broadcast on comp.lang.perl.misc:


> I have this MySQL table:

Sorry.  Wrong group.


-- 
        Lars Eighner <http://larseighner.com/> usenet@larseighner.com
               War on Terrorism: Treat Readers like Mushrooms
 "DO NOT USE photos on Page 1A showing civilian casualties from the U.S. war
          on Afghanistan." -Memo, _Panama City_ (FL) _News Herald_


------------------------------

Date: Sun, 7 Dec 2008 20:07:52 -0800 (PST)
From: Harry <simonsharry@gmail.com>
Subject: wget/sftp- style progress bar
Message-Id: <9cae2ddb-0e96-419e-ac03-536e34ba7b40@d23g2000yqc.googlegroups.com>

Hello,

I have a list of length operations I need to carry out. For each item
in this list, I want to display current progress on a single line only
(instead of multiple lines per item) as is done by such programs as
wget and sftp.

Now, I can obviously use the <backspace> character to seek to earlier
point on the current line. But before I do all of that manual and ad
hoc computations, I'm wondering if there's any helpful package that
has already though through this problem... so that I deal only in
higher abstractions such as fields, field lengths, left/right
justified field value, truncate field value (vs extend field length if
value is longer), etc.

Regards,
/HS


------------------------------

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 2040
***************************************


home help back first fref pref prev next nref lref last post