Re: calculating a list..



In article <1119974005.782965.254510@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Dave <david.samuelsson@xxxxxxxxxxxxxxxx> wrote:

: sorry i didn't correct the example data to be written. What i want to
: accomplish is actually the tree as
:
: - tree
: -node1
: -node1.1
: -node1.1
: -node1.1
: -node1.1
: -node2
: -node2.1
: -node2.1
: etc..indefinetly

Do you want a code generator for the Javascript tree?

$ cat tree
#! /usr/local/bin/perl

use warnings;
use strict;

sub usage { "Usage: $0 kids grandkids-per-kid\n" }

## main
die usage unless @ARGV >= 1;

my($kids,$grandkids) = @ARGV;
$grandkids = 4 unless defined $grandkids;

print "d.add(0,-1,'tree');\n";

my $id = 1;
for (my $k = 1; $k <= $kids; $k++) {
my $parent = $id++;
print "d.add($parent,0,'Node $k');\n";

for (my $gk = 1; $gk <= $grandkids; $gk++) {
my $text = "Node $k.$gk";
print "d.add($id,$parent,'$text');\n";
++$id;
}
}

$ ./tree 3
d.add(0,-1,'tree');
d.add(1,0,'Node 1');
d.add(2,1,'Node 1.1');
d.add(3,1,'Node 1.2');
d.add(4,1,'Node 1.3');
d.add(5,1,'Node 1.4');
d.add(6,0,'Node 2');
d.add(7,6,'Node 2.1');
d.add(8,6,'Node 2.2');
d.add(9,6,'Node 2.3');
d.add(10,6,'Node 2.4');
d.add(11,0,'Node 3');
d.add(12,11,'Node 3.1');
d.add(13,11,'Node 3.2');
d.add(14,11,'Node 3.3');
d.add(15,11,'Node 3.4');

Hope this helps,
Greg
--
Security engineering involves programming Satan's computer. And Satan's
computer is hard to test.
-- Bruce Schneier
.



Relevant Pages

  • Re: Female watchmakers
    ... Frank Adam wrote: ... and do accomplish many things beyond traditional home-maker based ... technical and scientic pursuits is no longer the exception to the rule. ... Go hug a tree. ...
    (alt.horology)
  • Re: Network stack cloning / virtualization patches
    ... > be stripped down to minimal, clean, well-architected diffs to accomplish ... > gets too close to the tree. ... virtualize and which not. ... but I hope to hear some feedback though... ...
    (freebsd-hackers)
  • Re: Network stack cloning / virtualization patches
    ... > be stripped down to minimal, clean, well-architected diffs to accomplish ... > gets too close to the tree. ... virtualize and which not. ... but I hope to hear some feedback though... ...
    (freebsd-net)
  • #inject:into: What a Gem!
    ... bracketed notation of a tree ... I was able to accomplish this with merely the following code: ... This kind of parsing is usually a mess in other languages. ...
    (comp.lang.smalltalk.dolphin)
  • Re: UI Design Question
    ... I already have the table design hammered out - but how to dislay it all ... I suppose a "brute force" method would involve ... >> but a bit more complicated than a simple tree or set of inverted trees. ... I'd appreciate some suggestions for how to accomplish this ...
    (microsoft.public.dotnet.framework.aspnet)