in reply to Print Current Program Source Code

Hi Samy_rio,

Another way to do it in Linux:

use strict; use warnings; system("cat $0");

If your on a Windows box, change cat to type, and consider adding quotation marks (for the likely case of a filename with spaces in it):

use strict; use warnings; system("type \"$0\"");

s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^2: Print Current Program Source Code
by davorg (Chancellor) on Aug 18, 2006 at 10:30 UTC

    You can have spaces in filenames on Linux (and Unix) too. And using qq// would avoid all that ugly escaping.

    system(qq(cat "$0"));
    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      and
      system('cat', $0);
      would need no quoting at all =)

      update: actually only system(cat => $0); really needs no quotes... isn't that elegant?

Re^2: Print Current Program Source Code
by davidrw (Prior) on Aug 18, 2006 at 12:47 UTC
    or just:
    open SRC, '<', $0 or die; print for <SRC>; close SRC;