Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Directory opening script

Status
Not open for further replies.

chrismassey

Programmer
Aug 24, 2007
264
GB
Hi,

I have a simple script which is designed to take the value from a textbox, combine it with the path and to open that directory. I recieve an Error 500 and i'm not sure why...

Code:
########## Opening Tags
#! /usr/bin/perl
use strict;

########## Declare variables
my ($initial_path, $open1, $open2, $openb1, $openb2, $path, @directory_contents1, @directory_contents2);

########## Connect to form
##### Path textboxes
$open1 = param('open1');
$open2 = param('open2');
##### Path open buttons
$openb1 = param('openb1');
$openb2 = param('openb2');

######### Path to z directory
$initial_path = "/PATH/ChrisMassey.co.uk/Perl/Scripts/ControlPanelV1.0/Test";

########## Check which open button was pressed
if ($openb1) {
##### The path is...
$path = "$initial_path . ' ' . $open1";
}
else {
##### The path is...
$path = "$initial_path . ' ' . $open1 . ' ' . $open2";
}

########## Open directory
opendir (LOGDIR, "$path") || Error ('open', 'directory');
@directory_contents1 = readdir (LOGDIR);
closedir (LOGDIR);
##### Sort contents into alphabetical order
@directory_contents2 = sort @directory_contents1;

########## Print contents
##### Print form at the top
print "Content-type: text/html\n\n";
print <<"HTML code";
<HTML>
<HEAD>
<TITLE>Webspace Explorer Control Panel</TITLE>
</HEAD>
<BODY>

<FORM ACTION="script.pl" METHOD=POST>
<p><input type="text" name="open1" size="50"><input type="submit" value="Open" name="openb1"></p>
<p><input type="text" name="open2" size="50"><input type="submit" value="Open" name="openb2"></p>
</FORM>

</BODY>
</HTML>
HTML code
##### Print directory contents beneath
foreach (@directory_contents2) {
print "Content-type: text/html\n\n";
print "$_";
}

########## File opening error
sub Error {
print "Content-type: text/html\n\n";
print "<font face=arial size=2><P>Cannot Open File/Directory... Error 1.</font>";
exit;
}

Thanks in advance

Chris
 
Okay i've narrowed it down to my use of . ' ' . I think???
 
Okay sorry, fixed my problem... I removed the spaces across the . ' ' . (therefore .''.).

Chris
 
this is totally unnecessary ayway:

$path = "$initial_path . ' ' . $open1 . ' ' . $open2";

can be written as:

$path = "$initial_path$open1$open2";

you are getting no benefit from using concatenation since you're assigning the value to a new string. Anyway you look at it perl has to make a new string so just use quotes to make the new string unless you prefer concatenatin for some reason.




------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thanks Kevin,

In the past I have tried putting scaler variables together like $a$b$c but because of the context I was using them it didn't work, so I have a habit of connecting scalers like that. I have removed them now

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top