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
 
Try this...
Change this:
Code:
@info = stat($fullUnit);
$fileSize = $info[7];

To this:
Code:
$fileSize = -s $fullUnit or die "Bad file$!";

How does this work for you?

X
 
By the way, I know that it would really help you with future posts if you read the following links. We would really appreciate it!

faq219-2884
faq219-2889

Just trying to help!

X
 
X,

Thanks for the tip, but I'm not sure what you're referencing with the last post. What didn't I do correctly?

- MT
 
That gives me "bad file No such file or directory" which is simply not true.

- MT
 
Have you read the links I gave you yet? I'm not saying you "did something wrong or incorrect"...

I just think (know from experience :) that reading these FAQs would increase your response ratio & time.

I'm just trying to help!

X
 
That gives me "bad file No such file or directory" which is simply not true.

How can you be so sure?

This is probably the same reason you received your initial error:
User of uninitialized value in concatenation (.) at line 62
## which is this " print "<td>" . $fileSize . "</td>\n"
 
I can be sure because I'm sitting right next to the server.

Let's start a little easier. I need to be able to get the size and date of creation of a file. Here's the code as it currently is in working condition:

#!/usr/bin/perl -wT

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

opendir (FTPDIR, "/var/ || Error ('open', 'directory');


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=80% class=tableHeader>Name</td>
<td width=7% 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>/ Folder Name </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) {
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>[SIZE]</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>";
}
}
}

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

So in that first if statement, I need to create something that will replace [DATE] and [SIZE] with actual variables.

- MT
 
mtorbin

Are you SURE that you don't need to chomp the @folderContents before you iterate through them?

This example will reinforce my point:-

Code:
[b]#!/usr/bin/perl[/b]

@folderContents = `ls -1`;

foreach $item (@folderContents) {
  print "_${item}_\n";
}

outputs:-

_Applications
_
_Desktop DB
_
_Desktop DF
_
_Library
_
_Network
_
_System
_
_User Guides And Information
_
... etc

i.e. there is a hard return after every item - so they would need to be chomped to be able to use


Kind Regards
Duncan
 
In its current form it returns no errors.

- MT
 
mtorbin,

The problem may be that you are not giving the stat() the path to find the file with.

Try this:
Code:
 if ($extension) {
        my @info = stat("/var/[URL unfurl="true"]www/html/effTeePee/$fullUnit");[/URL]
        my $fileSize = $info[7];

Your layout looks good.

I'm bettin' you are gonna know alot more PERL when you get through with this...

Thanks,
 
LM -


Thanks... yeah, that's the plan. To "learn more". ; )

- MT
 
OK, I have this working, but I must becoming a real programmer because the burning question of "WHY?" is in my head. Here's the code block:

my $currentFolder = substr $ENV{"QUERY_STRING"},17;
my $currentDirectory = "/var/ . $currentFolder;

8:
9: opendir (FTPDIR, $currentDirectory) || Error ('open', 'directory');
10: ## opendir (FTPDIR, "/var/ || Error ('open', 'directory');
11:
Now here's the url that passes the variable:

../cgi-bin/listFiles.cgi?currentDirectory=effTeePee

Now, to me that seems a bit clugey. If I change the above to this:

../cgi-bin/listFiles.cgi?currentFolder=effTeePee

I get the following error:

Undefined subroutine &main::Error called at line 9

What's the deal?

- MT
 
Hi

The word currentDirectory is 16 character long, the currentFolder is just 13. Plus 1, the equal sign. So change this too :
Code:
my $currentFolder = substr $ENV{"QUERY_STRING"},[red]14[/red];

Feherke.
 
Don't worry that burning sensation it only lasts a little while..

Code:
 opendir (FTPDIR, $currentDirectory) || Error ('open', 'directory');

With this line you've told PERL that if there is a problem with the "opendir (FTPDIR, $currentDirectory)"
to use the function "Error" to report the problem.

You have not defined your Error Function.

This is what I use:
Code:
 opendir (FTPDIR, $currentDirectory) || dienice($!);

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

This is good for testing.

Thanks
 
Sorry for the misinformation...

In PERL the subroutines are called "subs" not "functions".

You should strongly consider moving toward CGI, you will find
that it is much easier to deal with.

somecgi.pl
Code:
use strict;

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);

print header;
print start_html('My First CGI');
my $testValue;

if(param("Dir")){
$testValue = param("Dir");
}
else {
$testValue = "that was default";
}

print "We used the value $testValue for this variable.";

print end_html;

Try calling the example above with:
somecgi.pl?Dir=effTeePee

Thanks,
 
That being said, why is this portion not working? It seems pretty straight forward to me:

my $currentFolder = substr $ENV{"QUERY_STRING"},14;

if ($currentFolder) {
my $currentDirectory = "/var/ . $currentFolder;
}

else {
my $currentDirectory = "/var/}

opendir (FTPDIR, $currentDirectory) || Error ('open', 'directory');

Basically, if nothing is passed over in $currentFolder, then $currentDirectory should be initialized and given the value of "/var/ If something IS passed over, then the value should be "/var/ . $currentFolder, right?
 
Try this:
Code:
my $currentFolder = substr $ENV{"QUERY_STRING"},14;
my $currentDirectory;
my $length = length($currentDirectory);
if ($length > 0) {
    $currentDirectory = "/var/[URL unfurl="true"]www/html/"[/URL] . $currentFolder;
}

else {
    $currentDirectory = "/var/[URL unfurl="true"]www/html/effTeePee";[/URL]
}

opendir (FTPDIR, $currentDirectory) || Error ('open', 'directory');

Is that what your are looking for?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top