tej has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

I am reading somebody else's script and I found code like

while(-d $dest_book){ ##Some code }

What does "-d" means?

I also found

if(-f $path_browsefile){ ##Some code }

Here what is -f?

Are there more such options in perl?..If yes where can I find their reference?

Thanks

Update: Thank you Monks.. This was helpful :)

Replies are listed 'Best First'.
Re: What are -d and -f for?
by graff (Chancellor) on Aug 13, 2011 at 05:48 UTC
    You want to read the output of perldoc -f -X (the "-f" tells perldoc to display the portion of the massive perlfunc manual that explains all the '-X' built-in functions, which include: -e -d, -f, -s, -r, -M and many other useful things.

    The '-X' functions are all concerned with getting details about files: -d $filename returns true if $filename exists and is a directory; -f $filename returns true if $filename exists and is a data file.

Re: What are -d and -f for?
by GrandFather (Saint) on Aug 13, 2011 at 06:16 UTC

    -d takes a string parameter (possibly in $_) and returns true if the string represents the path to a directory. -f does the same but tests for the path being that of a file. These and a slew of other related functions are described in perlfunc at the start of the alphabetical listing of functions.

    True laziness is hard work
      Thank you for renaming it.. Will take care next time..
Re: What are -d and -f for?
by Jim (Curate) on Aug 13, 2011 at 05:49 UTC

    These are Perl's -X file test operators. They're documented in perldoc -f -X. See -X.

Re: What are -d and -f for?
by johngg (Canon) on Aug 13, 2011 at 15:12 UTC

    Other Monks have given you the answer to your question and advice on how to access the documentation. This is to bring to your attention, should you be working in a *nix environment, the fact that a symbolic link to a directory will also give a positive with the -d file test operator. If you wish to distinguish between directories and symbolic links that point to directories you will also have to use the -l file test.

    knoppix@Microknoppix:~/data$ mkdir mydir knoppix@Microknoppix:~/data$ ln -s mydir mylink knoppix@Microknoppix:~/data$ ls -l total 4 drwxr-xr-x 2 knoppix knoppix 4096 Aug 13 15:52 mydir lrwxrwxrwx 1 knoppix knoppix 5 Aug 13 15:52 mylink -> mydir knoppix@Microknoppix:~/data$ perl -E ' > say q{-} x 40; > foreach my $thing ( qw{ mydir mylink } ) > { > say > qq{-d test says $thing is }, > -d $thing > ? q{} > : q{not }, > q{a directory}; > say > qq{-l test says $thing is }, > -l $thing > ? q{} > : q{not }, > q{a symlink}; > say q{-} x 40; > }' ---------------------------------------- -d test says mydir is a directory -l test says mydir is not a symlink ---------------------------------------- -d test says mylink is a directory -l test says mylink is a symlink ---------------------------------------- knoppix@Microknoppix:~/data$

    I hope this is helpful.

    Cheers,

    JohnGG

Re: What are -d and -f for?
by Anonymous Monk on Aug 13, 2011 at 08:51 UTC