"Janek Schleicher" <[EMAIL PROTECTED]> writes: > Well, yes of course I can run each filename thru all those tests, but that >> seems kind of like a lot of huffing and puffing. I wondered if there >> isn't something that just spits it out. >> >> perl `stat' does do that very thing in element[2] ($mode) but extracting >> `type' from that number looks hideously complicated. >> >> Maybe running all possible tests is quicker and easier after all. It would >> really come down to just these: >> -f -d -l -b -c -p -S >> But all that info is available in @elems = (stat "fname"); >> >> Unix `stat' actually spits it out in plain english, what type it is. (at >> least gnu `stat' does) > > If you write instead > if (-f $file) { > # > } elsif (-d _) { > # ^ > } > > Then there is no extra stat call. > The underscore _ holds the results of the last stat call (implicitly > called by the -f operator), so no unnecessary work needs to be done. > > So you gain all stat informations in equivalent access time, but with a > much improvement in readability. > > (A typical statement of my programs look e.g. like > if (-e $file && -f _ && -M > 3) { ... > # process existing files, older than 3 days > } > )
I've seen that `_' crop up before I don't understand what this means. What `result' are we talking about here, inside _? exit status .. TRUE or FALSE? 0 or 1 ... filename what? $file = shift; if(-f $file ){ print _ . "\n"; } Results>>> _ Further: Won't your code try to process symlinks too? ( Maybe that is desireable though) Or maybe symlinks are regular files. But then why is there a -l test? consider ls -l file* -rw-rw-r-- 1 reader reader 5 Jun 9 16:39 file lrwxrwxrwx 1 reader reader 5 Jun 9 16:35 file_link -> file cat test2.pl #!/usr/local/bin/perl -w $file = shift; if (-e $file && -f _ ) { print "Perl passed <$file> as both existing and a regular file\n=== === === ===\n"; print "Unix \`file' reports:\n" , qx( file $file); } Run it: ./test2.pl file_link $ ./test2.pl file_link Perl passed <file_link> as both existing and a regular file === === === === Unix `file' reports: file_link: symbolic link to file -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]