in reply to Re^3: Unsuccessful stat on file test
in thread Unsuccessful stat on file test

By gum! With your help (and the help of the other posters)...I think I've got it! Hard work do pay off! Well, the prog isn't quite finished. There's still some debugging messages in there, and some tidying up to do.

But basically it is now in a workable state. If I feed the program (which is named ex1-11, short for exercise 1 chapter 11) files with different modes, it will accuratley reflect those modes.

Here's what I came up with:
#!/usr/bin/perl use warnings; use strict; sub filetest { my @answer; print "\n\$_[0] now holds $_[0] \n"; return "File does not exist\n" unless -e $_[0]; push @answer, "readable " if -r $_[0]; push @answer, "writable " if -w $_[0]; push @answer, "executable " if -x $_[0]; print "function result: "; print @answer; return @answer; } while (@ARGV) { my $file = shift @ARGV; $file =~ s/\s*$//; print "\$file is $file"; my @answer = filetest($file); #thanks for the style tip! print "\nmain answer: "; print @answer; print "\n"; }
Where I was falling down (mainly) was in the subroutine where I was confusing $_ with $_[0]. It was a few chapters ago, and sort of leaked out of my brain. There's a lot to retain to this Perl stuff! ;)

Just wanted to dash off this note as a thanks to everyone who commented. I will try to finish up this program and begin the next one on the train into NYC tommorow.

G'night, Monks!