On Oct 3, 2013, at 11:51 AM, Harry Putnam wrote: > Uri Guttman <u...@stemsystems.com> writes: > > [...] > >>> ,---- >>> | script.pl ./td >>> | $eperm = (stat(./td/./td))[2] >>> | $eperm = (stat(./td/./td/three))[2] >>> | $eperm = (stat(./td/./td/one))[2] >>> | $eperm = (stat(./td/./td/two))[2] >>> `---- >>> >>> That will be a non-working comparision >> >> in your original code and output you printed $File::Find::name and it >> only showed the file part and not the dir. maybe you had an empty dir >> there but that is what i was basing my comment about. stat would fail >> unless it had the dir in the path. that would be the cause of your >> undef warning. > > I don't think that is really all of it either. > > If you use Johns' formulation: > > my $var = (stat)[2]; > > That is not including the directory either... but it works. > > In fact that truly is using just the end file name $_. > > So doesn't it mean that inside find() the program is changing dir > right along with the search for executable files? That is, every time > the search digs a directory deeper, `stat' is called inside that > level. > > Isn't that the only way that '$_' would consistently work in stat? > > The only way directory + file would work consistently would be > to only `stat' absolute file names.
Have you read the documentation for the File::Find module? Before the find() subroutine is called, the module changes default directory to the directory containing the file being passed to find(). The name of the file (without its full path) is in the $_ variable. The full path name is in $File::Find::name. Therefore, either stat() or stat($File::Find::name) should work, and your undefined problem lies elsewhere. In general, the simplest way to solve problems of this type is to print out the values within your program. At the beginning of the find() routine, print out the values of $_, $File::Find::name, and $File::Find::dir (the directory containing the file in $File::Find::name). Then print out the value of $eperm after calling the stat() function. If you can't figure out from all of that what the problem is, post your results here and ask for help. For debugging purposes, I usually declare a variable at the top of my program: my $debug = 1; Then I sprinkle print statements controlled by this variable throughout my program: print "\$_=$_\n" if $debug; When my program is debugged and ready to run, I change the declaration of $debug to this: my $debug; and the print statements are turned off. I also usually define a command-line option (-d) that sets $debug to true, allowing me to turn debugging on and off at will. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/