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

Like cwd to get the current working directory i just watn to display the current file name whatever perl in process. In otherwords i am in a script "test.pl". i just want to print the same.

Replies are listed 'Best First'.
Re: Current file name
by lostjimmy (Chaplain) on Jun 06, 2009 at 12:13 UTC
Re: Current file name
by toolic (Bishop) on Jun 06, 2009 at 12:24 UTC
    If you just want the name of the file, without the path use File::Basename:
    use File::Basename; my $name = basename($0);
Re: Current file name
by GrandFather (Saint) on Jun 06, 2009 at 12:17 UTC

    $0. See perlvar


    True laziness is hard work
Re: Current file name
by Anonymous Monk on Jun 06, 2009 at 21:58 UTC
    use FindBin qw($Script); print $Script, "\n";
    or
    use File::Basename; print basename(__FILE__), "\n";
Re: Current file name
by JavaFan (Canon) on Jun 06, 2009 at 12:35 UTC
    There's no such concept as a "current file name". After the process has started, the file may have been deleted, copied, moved or modified. On top of that, the program executed may come from STDIN, or from the command line.
      Don't you get the same set of problems with cwd? I'd say you are overthinking things.
        Don't you get the same set of problems with cwd?
        No.