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

beginner question: how to check whether the given input is a file or folder ?
if -f $path { do something }
is it correct , i need to check the given path is a file or folder ?

Replies are listed 'Best First'.
Re: how to check
by balakrishnan (Monk) on May 23, 2009 at 08:52 UTC
    if (-f $ARGV[0]) { print "file"; } elsif(-d $ARGV[0]) { print "dir"; }
    -f option is used to check whether the argument is a file or not.
    -d option is used to check whether the argument is a directory or not.
Re: how to check
by ig (Vicar) on May 23, 2009 at 08:43 UTC

    Your test will be true if $path is the path of a file. You can use '-d' to test if it is the path of a directory. Too see all the tests you can read -X

Re: how to check
by Anonymous Monk on May 23, 2009 at 08:42 UTC