1753449 Members
6132 Online
108794 Solutions
New Discussion

Re: Basic perl script

 
SOLVED
Go to solution
H.Merijn Brand (procura
Honored Contributor

Re: Basic perl script

Just How I would write it ...

--8<---
#!/usr/bin/perl

use strict; # Never write without it
use warnings; # Shows you what you wanted to know

my $html_file = "/var/apache/htdocs/tmp1.html";
unlink $html_file;
open my $html, ">", $html_file or die "$html_file: $!";

foreach my $ifile (glob "/var/apache/htdocs/cfg/*.cfg") {
print STDERR "$ifile ...\n";
local (@ARGV, $/) = ($ifile);
$lines = <>;

(my $dist_name = $ifile) =~ s{.*/[^/]+.cfg$}{$1};

print $html << EOH;


Welcome to Infoman Report Centre
<meta http-equiv="refresh" content="60#" />
< circle="" outside="">
MRTG Statistics for Distribution $dist_name




EOH

while ($lines =~ m{^Target(.*?)}mgs) {
my $stanza = $1;
my ($url) = $stanza =~ m{\[(.*?)\].*};
my ($desc) = $stanza =~ m{.*Description:(.*?).*}i;
print $html qq{Desc: $desc\n",
\n";
print STDERR "-" x 40, "\n";
}
}

print $html "\n\n";
close $html;
-->8---

Though I have serious doubt about this whole script.

I have already altered you HTML generation, as it was very wrong. Mine still isn't w3c compliant, but I have removed several parts already.

You are generating a single html file with several starts, each had two calls in your original,
inside a section and much more.

Have a look at the final outcome, and see if this is really what you want. I hope it's not.

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn