#!/usr/bin/perl # Object tree - Alt content creator. # Copyright (C) November 2000 Neil Fraser # http://neil.fraser.name/software/tree # This program is free software; you can redistribute it and/or # modify it under the terms of version 2 of the GNU General # Public License as published by the Free Software Foundation. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # http://www.gnu.org/ # Use this code-block if you want to input data from a form. use CGI; my $query = new CGI; my @data = split(/\n/, $query->param('data')); # Use this code-block if you want to input data from a file. #open (FILE, '/home/httpd/html/data.txt') || die "Can't open data file: $!"; # my @data = ; #close (FILE); print "Content-type: text/plain\n\n"; $oldlevel = 0; foreach (@data) { next if (/^\s*$/); # Skip blank lines. s/\n//g; s/\r//g; # Strip linebreaks. # Parse the line into level, text and url components. /^(\s*)(.+)/; $level = length($1); $_ = $2; if (/(.*)\|\s*([^|]*)$/) { $text = $1; $url = $2; } else { $text = $_; $url = ''; } $text =~ s/\s+$//; # Trim trailling spaces. $url =~ s/\s+$//; # Print any required tags. for ($i = $oldlevel; $i < $level; $i++) { print ' 'x$i."\n"; } $oldlevel = $level; # Print the current line. print ' 'x$level.'
  • ' if $level; if ($url) { print "$text\n"; } else { print "$text\n"; } } # Close any open \n"; }