Generate HTML from a Windows Network Share

R

rob

Hello, I'm curious if anyone knows of a way to generate an HTML
document based on information gathered on a windows network share?
 
J

Josef Moellers

rob said:
Hello, I'm curious if anyone knows of a way to generate an HTML
document based on information gathered on a windows network share?

What part are you having problems with:
- gathering information on a windows network share
or
- generate an HTML document
Where do you expect problems?

What have you tried so far? Where have you failed?
 
R

rob

I'm mostly investigating the possible viability of doing this. Please
bear with me as I am very much a newbie when it comes to perl.
From my understanding, the code for gathering the data would be
something like this (if I'm not totally mistaken ..... which is very
possible):

$path "\\network_share\"

opendir($path) \ die "Can't open $path";
@dirs=["other"];
closedir(dir)

print "<a href="\"$path">Test</a>

Am I looking at this in the right direction?
 
I

Ian Wilson

I'd start with

#!perl
use strict;
use warnings;
$path "\\network_share\"

I'm probably over simplifying but ...
1. To assign a value to a variable use the equals sign.
2. Use single quotes unless interpolating variables into text.
3. It is usually prudent to use forward slashes not back slashes.
4. Terminate a statement with a semi-colon.
opendir($path) \ die "Can't open $path";

1. Use the vertical bar for a high precendence "or".
2. For this circumstance, I prefer the word "or" instead.
(there are precedence pitfalls for the unwary)
@dirs=["other"];

You probably need to use the readdir() function here.
closedir(dir)

Missing semi-colon.
print "<a href="\"$path">Test</a>

1. Unescaped superfluous quote after href=.
2. You didn't escape the other quote after the path.
3. No terminating quote.
4. No semi-colon.

You probably want to print the filenames you just read.
Am I looking at this in the right direction?

Yes, but you might need to consult an optician :)

You might find it helpful to start by writing a tiny program and
actually try seeing what Perl tells you about syntax errors!

There are CPAN modules that simplify reading filenames from a directory.
 
T

Tad McClellan

rob said:
I'm mostly investigating the possible viability of doing this.


It is most certainly viable. (if "viable" means "possible".)

Please
bear with me as I am very much a newbie when it comes to perl.
$path "\\network_share\"
^^
^^ statements in Perl usually end with a semicolon;

Am I looking at this in the right direction?


No.

You should start with writing a Perl program that prints:

Hello world!

Then modify it a little bit at a time, each time getting a little
closer to your real objective.

See:

http://learn.perl.org
 
R

rob

That was incredibly helpful. :)

I do have one more question thought..

I've now got the program reading a specified directory, gathering the
data from the directory and then outputting it to an html file just
fine ... however, I'd like to include the subdirectories that are
located in that directory .... is there a way to do this? Or will I
simply have to write a new section of code for each subdirectory that I
want to include in this report?

Here's an example of my code ::

my($my_path) = ('c:\\other\\');

opendir (DIR, $my_path) or die "Can't open $my_path";

my(@files) = grep {/.+\.\w{3}$/i} readdir(DIR);

closedir(DIR);

open (MYFILE, '>data.html');
foreach my $filename (files){print MYFILE "$filename\n";}

close (MYFILE);



Ian said:
I'd start with

#!perl
use strict;
use warnings;
$path "\\network_share\"

I'm probably over simplifying but ...
1. To assign a value to a variable use the equals sign.
2. Use single quotes unless interpolating variables into text.
3. It is usually prudent to use forward slashes not back slashes.
4. Terminate a statement with a semi-colon.
opendir($path) \ die "Can't open $path";

1. Use the vertical bar for a high precendence "or".
2. For this circumstance, I prefer the word "or" instead.
(there are precedence pitfalls for the unwary)
@dirs=["other"];

You probably need to use the readdir() function here.
closedir(dir)

Missing semi-colon.
print "<a href="\"$path">Test</a>

1. Unescaped superfluous quote after href=.
2. You didn't escape the other quote after the path.
3. No terminating quote.
4. No semi-colon.

You probably want to print the filenames you just read.
Am I looking at this in the right direction?

Yes, but you might need to consult an optician :)

You might find it helpful to start by writing a tiny program and
actually try seeing what Perl tells you about syntax errors!

There are CPAN modules that simplify reading filenames from a directory.
 
J

Josef Moellers

rob said:
That was incredibly helpful. :)

I do have one more question thought..

I've now got the program reading a specified directory, gathering the
data from the directory and then outputting it to an html file just
fine ... however, I'd like to include the subdirectories that are
located in that directory .... is there a way to do this? Or will I
simply have to write a new section of code for each subdirectory that I
want to include in this report?

Look at the File::Find module.
 
I

Ian Wilson

rob said:
I've now got the program reading a specified directory, gathering the
data from the directory and then outputting it to an html file just
fine ... however, I'd like to include the subdirectories that are
located in that directory .... is there a way to do this? Or will I
simply have to write a new section of code for each subdirectory that I
want to include in this report?

Josef has given the 'best practise' answer to this. The old fashioned
answer is to use recursion. You could modify your program, put the
directory scanning code in a subroutine, pass the starting directory as
a parameter. Then, when iterating over the list of files you use the
'-d' test to see if the file is in fact a directory, if so call the
subroutine from witin itself to process the subdirectory.

Your code is a bit old fashioned so I've added some suggestions:
Here's an example of my code ::

my($my_path) = ('c:\\other\\');

You don't need brackets around a list of one element
my $my_path = 'c:\\other\\';
opendir (DIR, $my_path) or die "Can't open $my_path";

Current best practise is to
- use lexical filehandles:
opendir my $dirhandle, $my_path
- include error cause ($!) in message:
or die "can't open $my_path because $!";
my(@files) = grep {/.+\.\w{3}$/i} readdir(DIR);

closedir(DIR);

open (MYFILE, '>data.html');

or die "Can't open data.html because $!";
foreach my $filename (files){print MYFILE "$filename\n";}

Are you re-typing rather than cutting and pasting? That should be
(@files) not (files).

It doesn't look much like HTML either :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,655
Latest member
eizareri

Latest Threads

Top