Harry Putnam wrote at Sat, 07 Jun 2003 02:18:32 -0700: >> So you can use: >> >> if (-f $file) { >> : >> # process file >> } >> elsif (-d $file) { >> : >> # process directory >> } >> } > 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 } ) Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]