Ryan Thomas <[EMAIL PROTECTED]> wrote:
: 
: I have a script below that lists a directory tree
: structure (thanks for the base code Jan!)and have
: modified it, unsuccessfully, to add the file size.
: 
: What have i done wrong ??
: 
: The output I am looking for is:
: 
: c:\anydir\foo.txt 1,102
: 
: code:
: 
: # Reads a directory tree and parses the results
: 
: # use strict; 
: use File::Find; 
: use File::stat;

    From File::stat:

  "This module's default exports override the core
   stat() and lstat() functions, replacing them with
   versions that return ``File::stat'' objects."


: use Cwd; 
: 
: print STDOUT "Enter the root of the path to be evaluated: ";
: $rootpath = <STDIN>; #path to be evaluated
: chomp $rootpath; #delete the trailing newline
: 
:  $dir = $rootpath; 
: 
:  print "Listing of $dir\n"; 
: 
: find ( sub { print qq{$File::Find::name\n};
: $size=(stat($File::Find::name))[7];

    A File::stat object is not an array. The eighth element
is undefined. Try:

my $size = ( stat $File::Find::name )->size;


: printf "size is %04o\n", $size;
: 
:  }, $dir );

    I found your error by turning strictures and
warnings on. I am not yet experienced enough to leave
them off.


#!/usr/bin/perl

use strict;
use warnings;

use File::Find;
use File::stat;
use Cwd;

print STDOUT "Enter the root of the path to be evaluated: ";
chomp( my $dir = <STDIN> );

print "Listing of $dir\n";

find (
    sub {
        print qq{$File::Find::name\n};
        my $size = ( stat $File::Find::name )->size;
        printf "size is \n", $size;
    },
    $dir
);
__END__


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to