Re: text to html

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On 07/03/2010 02:07 AM, Jozsi Avadkan wrote:
> input:
> http://pastebin.com/raw.php?i=MqPXZwc3
>
> output:
> http://pastebin.com/raw.php?i=8QCkp4yv
>
> it will be a long day.. :D
>
> could someone please help with it?
>
> i have to make a "one liner" that get's the input, and gives the
> mentioned output.
>    

Why a 'one liner'? That sounds an awful lot like homework...But I'll 
give you the benefit of the doubt. You can turn this Perl script into a 
one liner easily. Or you can just save it as a script and use it like:

./convert-to-html.pl < input_data.txt

#!/usr/bin/perl

use strict;
use warnings;

my (%section_info, @section_list);
while(<STDIN>) {
     s/^\s+//s;
     s/\s+$//;
     next unless ($_ ne '');
     s/&/\&amp;/gs;
     s/</\&lt;/gs;
     s/>/\&gt;/gs;
     s/"/\&quot;/gs;
     my ($dir,$file) = m#(^[^/]+)/(.+)$#;
     $file =~ s/\.html$//i;
     push(@{$section_info{$dir}}, "<a href=\"$_\">$file</a>");
     push(@section_list, $dir);
}
foreach my $section (@section_list) {
     print "<br><font size=4>$section</font><br>\n";
     print join(" |\n", @{$section_info{$section}});
     print "\n<br>\n";
}

-- 
Benjamin Franz
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos


[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux