Re: Tree-like data structures in Perl

2000-05-23 Thread Ranga

Eduard:
I am in need of the same thing. Just by coincidence I was thinking 
"wouldn't it be nice if...?" and Douglas's reply to your mail popped 
up.

One can easily use the File::Find t collect all the directories and 
files underneath and build a nice HTML table with indentation. 
However I would like to add collapse/expand actions using 
Javascript, which I have seen on a site. But this was cumbersome. 
If no one has done it in Perl (which I seriously doubt!) I can start 
with some coding. I would be very appreciative if someone can tell 
me how to do the collapse/expand... so I do not have to start from 
first principles.
Thanks...
Ranga Nathan
Reliance Technology Consultants Inc.

On 22 May 00, at 18:15, Douglas Wilson wrote:

Date sent:  Mon, 22 May 2000 18:15:57
Subject:        Re: Tree-like data structures in Perl
To: "Perl-Win32-Users Mailing List" 
[EMAIL PROTECTED]
From:   "Douglas Wilson" [EMAIL PROTECTED]
Send reply to:  "Douglas Wilson" [EMAIL PROTECTED]

 On 05/22/00, "Eduard Pandele [EMAIL PROTECTED]" wrote:
 
  This is my problem : I have to build a hierarchical menu in HTML from a
  tree of directories.
  Let's say I have this directory structure :
  
  root/
  root/one
  root/one/a
  root/one/b
  root/two
  root/three
  root/three/a
  
  I must get a series of html documents which should allow me to "walk"
  through the directories structure :
  
  index.html which contains the three links to one, two and three
  
  one.html which contains something like
  one
  - a
  - b
  two
  three
 
 I don't quite get what you're after, but maybe File::Find
 would help. It will traverse and cd (if desired) to every directory
 for you. Once in the directory, you could use
 opendir/readdir/closedir to read all the directories
 and/or files in the current directory.
 
 HTH,
 Douglas Wilson
 
 ---
 You are currently subscribed to perl-win32-users as: [EMAIL PROTECTED]
 To unsubscribe, forward this message to
  [EMAIL PROTECTED]
 For non-automated Mailing List support, send email to  
  [EMAIL PROTECTED]
 
 



---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
 [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
 [EMAIL PROTECTED]




Re: Tree-like data structures in Perl

2000-05-23 Thread Garrick Staples

You just want each page to have the links for the files/directories in that
immediate directory?  np...

## Warning, written on Unix, not tested in windows
# This creates an HTML page in each directory with links for that directory, like
a
# directory listing in a web browser.

$startingdir='/home/testsomething';
$index='index.html';

chdir $startingdir or die;
chdir '..';  # back up for a running start

$startingdir=(reverse split '/', $startingdir)[0]; #basename

link_maker($startingdir);  # recursive sub to do the work

sub link_maker {
   my $dir=shift;
   local (*INDEX, *DIR);

   return if -l $dir;# ignore links, do they exist on win32?
   chdir $dir or return; # can't read directory

   open INDEX, "$index" or do {chdir '..'; return}; #can't write here
   print INDEX qq{a href="../"..//abr\n} if ($dir ne $startingdir);

   opendir DIR, '.';
   foreach (readdir DIR) {
  next if /^\./ || /^$index$/;   # ignore $index and .files
  -d $_
 ? print INDEX qq|a href="$_/$index"$_//abr\n|
 : print INDEX qq|a href="$_"$_/abr\n|;
  link_maker($_) if -d $_;  # go recursive
   }
   close DIR; close INDEX;
   chdir '..';
}


Douglas Wilson wrote:

 On 05/22/00, "Eduard Pandele [EMAIL PROTECTED]" wrote:

  This is my problem : I have to build a hierarchical menu in HTML from a
  tree of directories.
  Let's say I have this directory structure :
 
  root/
  root/one
  root/one/a
  root/one/b
  root/two
  root/three
  root/three/a
 
  I must get a series of html documents which should allow me to "walk"
  through the directories structure :
 
  index.html which contains the three links to one, two and three
 
  one.html which contains something like
  one
  - a
  - b
  two
  three

 I don't quite get what you're after, but maybe File::Find
 would help. It will traverse and cd (if desired) to every directory
 for you. Once in the directory, you could use
 opendir/readdir/closedir to read all the directories
 and/or files in the current directory.

 HTH,
 Douglas Wilson

 ---
 You are currently subscribed to perl-win32-users as: [EMAIL PROTECTED]
 To unsubscribe, forward this message to
  [EMAIL PROTECTED]
 For non-automated Mailing List support, send email to
  [EMAIL PROTECTED]


---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
 [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
 [EMAIL PROTECTED]




RE: Tree-like data structures in Perl

2000-05-22 Thread Garold L. Johnson

You don't really need Per tree structures. The directory is already tree
structured, so what you need to do is to walk the directory tree producing
the output directly.

Walk a single level of the directory. If the file is a directory, either
process it immediately or place it in an array (a stack) and process the
included directories at the end.

Untested code:

sub dir_out
{
   my $dir = shift;
   my @dirs = (); # New stack at each level

   opendir( DIRH, $dir ) or die "Failed to open directory $dir: $! );
   my @files - readdir( DIRH );
   closedir( DIRH );

   # Emit the start of the HTML file here, generating names however you
choose

   foreach $file ( sort @files )
   {
  if ( -d $file )
  {
 # Save the directory
 push( @dirs, $file );
 # Emit link to lower HTML file as desired
  }
  else
  {
 # Emit HTML for $file hers
  }
   }  # @files

   # Finish this HTML file

   # Process directories recursively
   foreach $dir ( @dirs )
   {
  dir_out( $dir );
   }
}  # dir_out

This ignores issues of full path vs. file name, bunches of stuff about how
the HTML looks, and other niceties. It is intended only to demonstrate that
you already have a tree structure to walk, and that is in the directory
structure itself.

Thanks,

Garold (Gary) L. Johnson
DYNAMIC Alternatives

Eduard Pandele wrote
Hello !

This is my problem : I have to build a hierarchical menu in HTML from a
tree of directories.
Let's say I have this directory structure :

root/
root/one
root/one/a
root/one/b
root/two
root/three
root/three/a

I must get a series of html documents which should allow me to "walk"
through the directories structure :

index.html which contains the three links to one, two and three

one.html which contains something like
one
- a
- b
two
three

etc...

I could made up a simple program to do this, if only i could implement
somehow a tree data structure in Perl (after all, I should use a tree
construction algorithm and walk through this tree to generate the html
files).




---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
 [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
 [EMAIL PROTECTED]