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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can Somone Shed Some Light On This:

Status
Not open for further replies.

mtorbin

Technical User
Nov 5, 2002
369
US
Here's the code:

if (@folderContents) {
foreach my $indivFile (@folderContents) {
next if $indivFile=~m/^\.+$/;
my $fullUnit = $indivFile;
# escape the following "."
my ($name, $extension) = split (/\./ , $indivFile);

if ($extension) {
my @info;
my $info;
my $fileSize;

@info = stat($fullUnit);
$fileSize = $info[7];

print "<tr valign=top>\n";
print "<td align=center><img src=../images/icon_" . $extension . ".gif width=18 height=22></td>\n";
print "<td><a href=fileDownload.cgi?fileName=" . $fullUnit . ">$fullUnit<a></td>\n";
print "<td>[DATE]</td>\n";
print "<td>" . $fileSize . "</td>\n";
print "</tr>";
}

else {
print "<tr valign=top>\n";
print "<td align=center><img src=../images/icon_.gif width=20 height=22></td>\n";
print "<td><a href=listFiles.cgi?newDirectory=" . $fullUnit . ">$fullUnit<a></td>\n";
print "<td>&nbsp;</td>\n";
print "<td>&nbsp;</td>\n";
print "</tr>";
}
}
}

Here's the error:

User of uninitialized value in concatenation (.) at line 62
## which is this " print "<td>" . $fileSize . "</td>\n"

So what gives? I can't figure it out for the life of me. I'm sure it's something very obvious.

- MT
 
Hi

mtorbin said:
Name "main::currentDirectory" used only once: possible typo at /var/ line 16.
What is in line 16 ? I think you forgot the dolar sign before the variable name.

mtorbin said:
substr outside of string at /var/ line 6.
Code:
my $currentFolder = $ENV{"QUERY_STRING"}?substr($ENV{"QUERY_STRING"},14):"";

mtorbin said:
Undefined subroutine &main::Error called at /var/ line 16.
See Lrnmore's response above.

Feherke.
 
my $length = length($currentDirectory);

gives me the following error:

"use of uninitialized value in length
 
Hi

In Xagte's code the 3. line should be :
Code:
my $length = length($currentFolder);

Ps : I never use -wT options for [tt]perl[/tt]. I hate when an extremely flexible interpreter yells because uninitialised variables.

Feherke.
 
Sorry, but I'm just not seeing the problems here. Maybe I'm making more diffecult then it is. Here's the entire script:

#!/usr/bin/perl -wT
use integer;

print "Content-type: text/html\n\n";

my $currentFolder = $ENV{"QUERY_STRING"}?substr($ENV{"QUERY_STRING"},14):"";
## my $currentFolder = substr $ENV{"QUERY_STRING"},14;
my $currentDirectory;
my $length = length($currentFolder);

if ($length > 0) {
$currentDirectory = "/var/ . $currentFolder;
}

else {
$currentDirectory = "/var/}

opendir (FTPDIR, $currentDirectory) || dienice($!);


sub dienice {
print "<div style=\"color:red;\">Error ",$_[0],"</div>";
exit;
}


my @folderContents = readdir (FTPDIR);
closedir (FTPDIR);

print <<"HTML code";
<html>
<head>
<title>Untitled Document</title>
<link href=../ftpStyle.css rel=stylesheet type=text/css>
<script src=../jsLib.js></script>
</head>
<body>
<table width=80% border=0 align=center cellpadding=0 cellspacing=0>
<tr align=center valign=top>
<td width=19 height=20><img src=../images/box_gray_corner_tl.gif width=19 height=20></td>
<td background=../images/box_gray_side_t.gif><img src=../images/box_gray_side_t.gif width=2 height=20></td>
<td width=19 height=20><img src=../images/box_gray_corner_tr.gif width=19 height=20></td>
</tr>
<tr align=center valign=top>
<td background=../images/box_gray_side_l.gif><img src=../images/box_gray_side_l.gif width=19 height=2></td>
<td bgcolor=#f2f2f2>
<table width=100% border=0 cellspacing=5 cellpadding=0>
<tr valign=top>
<td width=3% align=center>&nbsp;</td>
<td width=70% class=tableHeader>Name</td>
<td width=17% class=tableHeader>Date</td>
<td width=10% class=tableHeader>Size</td>
</tr>
<tr valign=top>
<td align=center><img src=../images/icon_folderOpen.gif width=27 height=22></td>
<td>/</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
HTML code

if (@folderContents) {
foreach my $indivFile (@folderContents) {
next if $indivFile=~m/^\.+$/;
my $fullUnit = $indivFile;
# escape the following "."
my ($name, $extension) = split (/\./ , $indivFile);

if ($extension) {
my @info = stat("/var/ my $biteSize = $info[7];
my $fileSize = $biteSize/1024;

@date=localtime $info[9];
$date[5]+=1900; $date[4]++;


print "<tr valign=top>\n";
print "<td align=center><img src=../images/icon_" . $extension . ".gif width=18 height=22></td>\n";
print "<td><a href=fileDownload.cgi?fileName=" . $fullUnit . "&currentDirectory=" . $currentDirectory . ">$fullUnit<a></td>\n";
print "<td>";
printf "%02d/%02d/%04d %02d:%02d:%02d",@date[4,3,5,2,1,0];
print "</td>\n";
print "<td>" . $fileSize . "k</td>\n";
print "</tr>";
}

else {
print "<tr valign=top>\n";
print "<td align=center><img src=../images/icon_.gif width=20 height=22></td>\n";
print "<td><a href=listFiles.cgi?currentDirectory=" . $fullUnit . ">$fullUnit<a></td>\n";
print "<td>&nbsp;</td>\n";
print "<td>&nbsp;</td>\n";
print "</tr>";
}
}
}

print <<"HTML code";
</table>
<br>
<br>
</td>
<td background=../images/box_gray_side_r.gif><img src=../images/box_gray_side_r.gif width=19 height=2></td>
</tr>
<tr align=center valign=top>
<td width=19 height=20><img src=../images/box_gray_corner_bl.gif width=19 height=20></td>
<td background=../images/box_gray_side_b.gif><img src=../images/box_gray_side_b.gif width=2 height=20></td>
<td width=19 height=20><img src=../images/box_gray_corner_br.gif width=19 height=20></td>
</tr>
</table>
</body>
</html>
HTML code

If I don't use -wT, then I get premature end of script errors. Secondly, I have many files that have names with spaces. I need to put something in there that will find those files with spaces in their names. For example, a file named "this is me" will end up generating a link that looks like "?fileName=this". The "is me" part is completely chopped off. Thirdly, if I click on any of the directories, then I get a "no such file or directory" when I'm friggin' lookin' at it on the server!! Sorry, I'm almost at boing point.

- MT
 
firstly you will need to add double speech marks in your html...

[red]BAD[/red]
<img src=$variable>

[green]GOOD[/green]
<img src="$variable">


Kind Regards
Duncan
 
... and they will require escaping (i.e. a backslash before them) - as they are contained within double quotes


Kind Regards
Duncan
 
technically, as long as there are no spaces in the attribute it will work without quotes, but I would use quotes too.

This is a problem:

Code:
#!perl -w[b]T[/b]
.
.
.
my $currentFolder = $ENV{"QUERY_STRING"}?substr($ENV{"QUERY_STRING"},14):"";
.
.
.
opendir (FTPDIR, [b]$currentDirectory[/b]) || dienice($!);

You are using $currentDirectory to open a file but you have never untainted it. You must untaint the string before using it for anything "dangerous".

See this article:

 
Hi Kevin

mtorbin's previous post mentions that he is having problems with spaces - that is why i suggested using double quotes

"?fileName=this". The "is me" part is completely chopped off


Kind Regards
Duncan
 
mtorbin

This is not a reply to this post, but a note for the future. You've currently (24/Aug/05) got the top five threads on this forum, and they're entitled as follows:
[ul]
[li]Can Somone Shed Some Light On This:[/li]
[li]Help With My Sub[/li]
[li]What's a better way to write this?[/li]
[li]What am I missing?[/li]
[li]So what went wrong??[/li]
[/ul]
You'll have an (even) higher chance of getting help here if you give your threads more meaningful titles. It's also more friendly to others with similar problems in the future who are searching the archives of this forum.

For example, you could have called this thread "Use of uninitialized value in concatenation" - that way it could attract the attention of others getting that error, maybe with the same cause and solution.

Just something to bear in mind for the future.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Thanks all for the help. I'll be implimenting it today.

- MT
 
ChrisHunt,
Thank you very much! This was just the type of thing I was intending to say, but couldn't find a "correct" way of saying.... such as you did! Take a look at my reply on "22 Aug 05 15:01", wasn't I pointing him in the correct direction?

Thanks,

X
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top