Javascript and perl



Hello List,

Below is my index.pl

#!/usr/bin/perl

use Env;
print "Content-Type: text/html\n\n\n";
chdir("/path/to/dir");
@files=`ls -1`; ## load all the html files..

print "<html>\n";
print "<head>\n";
print <<END_SCRIPT;
<script>
function submit_form()
{
document.show_files.submit();
setTimeout(\"document.show_files.reset()\",3);
}
</script>
END_SCRIPT
print "</head>";
print "<body>\n";
print "<FORM NAME=\"show_files\" ACTION=\"display.pl\" METHOD=\"POST\"
target=\"_blank\" onsubmit=\"submit_form()\" >";
print "<p> \n</p>";
print "<table border=1 align=center >\n";
print "<tr><th> Multi site audit name</th><th> HTML Reports </th>\n
<th> CSV Reports</th></tr>";

print "<tr><td>Box 1</td><td>\n";
print "<SELECT NAME=\"box1\" SIZE=1>";
print "<OPTION SELECTED>HTML";
foreach $file (@files) {
chomp($file);
next if -d $file;
if (grep/Owner/, $file) {
($Owner,$month,$date,$year) = split/_/,$file;
$year =~ s/.html//g;
print "<OPTION>$month $date $year - Owner \n";
}
}
print "</SELECT>\n";
print "<INPUT TYPE=\"submit\" VALUE=\"GO\">\n";
print "</td></tr>";
print "</table>";
print "</FORM>\n";
print "</body>\n</html>\n";
exit 0;

This is my display.pl file...


#!/usr/bin/perl

&parse_form_data (*simple_form);
print "Content-type: text/html", "\n\n";
if ( grep/HTML/, $simple_form{'box1'}) {
} else {
$fileselect = $simple_form{'box1'};
}

chomp($fileselect);
@filename = split/ /, $fileselect;

foreach $type (@filename) {
if (grep/csv/,$type) {
$file =
$filename[4]."_".$filename[0]."_".$filename[1]."_".$filename[2].".csv";
$file_path="/file/path/$file";
break;
} else {
$file =
$filename[4]."_".$filename[0]."_".$filename[1]."_".$filename[2].".html";
$file_path="file/path/$file";
break;
}
}

if (grep /\.csv/,$file_path) {
} else {
open (READ, "<$file_path") || die "cannot open file:$!";
while (<READ>) {
print $_;
}
}
exit(0);

sub parse_form_data
{
local (*FORM_DATA) = @_;
local ( $request_method, $query_string, @key_value_pairs, $key_value, $key,
$value);

$request_method = $ENV{'REQUEST_METHOD'};

if ($request_method eq "POST") {
read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
}
@key_value_pairs = split (/&/, $query_string);
foreach $key_value (@key_value_pairs) {
($key, $value) = split (/=/, $key_value);
$value =~ tr/+/ /;
$value =~ s/%([\dA-Fa-f] [\dA-Fa-f]) /pack ("C", hex ($1))/eg;
if (defined($FORM_DATA{$key})) {
$FORM_DATA{$key} = join ("\0", $FORM_DATA{$key}, $value);
} else {
$FORM_DATA{$key} = $value;
}
}
} #End of sub routine;

index.pl displays the files in the drop down box and display box has to
display the file. That's it. It does the job in the abve code. but in IE I
get 2 windows poping up. I want to avoid it.
How can I do that?

Is there a better way to do this?

I just have to populate the files in a directory and display the same in a
new window.

Thanks in advance.


Cheers,
Umesh.


Relevant Pages

  • Re: This is driving me mad!!
    ... A very simple program to use as a sub routine. ... Pretty self explanatory take the number from level one DUP it store it and ... The problem you are have is the display is NOT refreshing. ...
    (comp.sys.hp48)
  • Re: cant write national characters - locales issue?
    ... miso@mysarge:~$ env ... miso@mysarge:~$ locale ... i know LC_NUMERIC and others that follow probably shouldn't display in ... quotes, but i don't think it matters, LC_CTYPE should play a role if i'm ...
    (Debian-User)
  • Re: Scientific Notation in Text Cell after Fill
    ... if I select the cell AND click in the Formula ... >text display, i.e., left aligned with no scientific ... >placing it in my Sub Routine but still Scientific ...
    (microsoft.public.excel.misc)
  • Re: WEB/CGI and environment var
    ... my goal is display all var which apper with command: env ...
    (comp.os.linux.development.apps)