in reply to Get filename of STDOUT

Bad news: even $0 won't work on all platforms. Win32, notably, does not support it.

Replies are listed 'Best First'.
Re^2: Get filename of STDOUT
by eserte (Deacon) on Aug 10, 2004 at 18:05 UTC
    Bad news: even $0 won't work on all platforms. Win32, notably, does not support it.
    ActivePerl 808 on Windows seems to support $0.
      Really? What does it say? (For named scripts; for one-liners?) Can you modify it?

      Last time I checked it said something useless like "perl.exe" or maybe nothing at all. That was in some 5.6 ActivePerl.

        ActivePerl build 810 (5.8.4) gives me the following:
        > perl -e "print $0" -e > echo print $0 >test.pl > perl test.pl test.pl
        5.6.1 on Linux gave me the same values for aproxamitly the same tests. (adjusting for shell differences)
        Setting $0 has no noticeable effect on windows that I could see.
        perl -e "print $0" prints -e. Oops, silly me! perl test.pl prints test.pl where test.pl is print $0;.
        >perl -v This is perl, v5.6.1 built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail) Copyright 1987-2001, Larry Wall Binary build 633 provided by ActiveState Corp. http://www.ActiveState. +com Built 21:33:05 Jun 17 2002