'ls' question, splitting and files with spaces in their name...

Madison Kelly linux-5ZoueyuiTZhBDgjK7y7TUQ at public.gmane.org
Sun May 23 15:43:16 UTC 2004


Hi Tim,

   I am trying to test this command with a mini script I wrte based on 
your suggestion but for the life of me I can't get the darn thing to 
tun. Can you see if I made an error somewhere?

=- Code
#!/usr/bin/perl
use CGI::Carp "fatalsToBrowser";
print "Content-type: text/html\n\n";

print "<pre>\n";
opendir(DIR, /home) or die "Can't open root: $!";
for (readdir(DIR))
{
	($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, 
$ctime, $blksize, $blocks) = stat($_);
	print "$dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, 
$mtime, $ctime, $blksize, $blocks\n";
}
closedir(DIR)
print "</pre>\n";
=- End Code

it keeps resulting in:

=- Error
Software error:

syntax error at /pwp/cgi-bin/tle-bu/tmp/dirtest.cgi line 13, near "print 
"</pre"
Can't find string terminator '"' anywhere before EOF at 
/pwp/cgi-bin/tle-bu/tmp/dirtest.cgi line 13.

For help, please send mail to the webmaster (root-bi+AKbBUZKZeoWH0uzbU5w at public.gmane.org), giving 
this error message and the time and date of the error.
=- End Error

There are very few ' " ' and so I can't seem to grasp what I am missing. 
This script is going to be very sensitive to performance because of how 
much it has to do so any place I can save even an iota of time will be a 
big help, Thanks!

Madison

Tim Writer wrote:
> Good advice but I'm a little surprised nobody mentioned readdir and stat.
> In other words, rewrite it (without ls) like this:
> 
>         opendir(DIR, $mnt_dir) or die "Can't open $mnt_dir: $!";
>         for (readdir(DIR)) {
>             ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
>              $atime,$mtime,$ctime,$blksize,$blocks) = stat($_);
>         }
>         closedir(DIR);
> 
> You get all the same information from stat that you got from "ls -l" but in a
> slightly different form and spaces are handled automatically.  In addition,
> you don't have the overhead of running ls in a separate process.


--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list