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

I want to be sticking output of simple scripts, onto the end of my script. Mainly, just because it would be convenient for answering/posing Perlmonks questions.

Currently I'm doing this

#filename: stickOutputOnEnd.pl use warnings; use strict; open F, ">>stickOutputOnEnd.pl"; print F "\nThis should be appended to my perl program."; close F; __END__ This should be appended to my perl program.
Works ok, but is there a more elegant way?

Replies are listed 'Best First'.
Re: Sticking output onto the end of your script.
by grinder (Bishop) on Mar 15, 2005 at 13:42 UTC

    What about:

    #! /usr/local/bin/perl -w open OUT, ">> $0" or die "erk: $!\n"; print OUT "$_\n" for @ARGV __END__

    - another intruder with the mooring in the heart of the Perl

Re: Sticking output onto the end of your script.
by perlfan (Parson) on Mar 15, 2005 at 14:43 UTC
    How about:
    #!/usr/bin/perl -w use strict; print "Hello, world\n"; __END__ Hello, world Hello, world Hello, world ...
    Then redirect the STDOUT at the commandline:
    #helloworld.pl >> helloworld.pl
      Duh! Okay, I'm doing that.
Re: Sticking output onto the end of your script.
by merlyn (Sage) on Mar 15, 2005 at 15:13 UTC
Re: Sticking output onto the end of your script.
by BrowserUk (Patriarch) on Mar 15, 2005 at 13:57 UTC

    Run, Select, Copy Alt-TAB, Paste :)


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco.
Re: Sticking output onto the end of your script.
by legato (Monk) on Mar 15, 2005 at 18:06 UTC
    The simple solution is to use this module I just whipped up (SelfRecord.pm):
    package SelfRecord; use strict; open SELF, '>>', $0 or warn("huh?: $!"); select SELF; $|=1; print "\n__END__\n"; 1;
    This is used simply, so that:
    #!/usr/bin/perl -w use strict; require SelfRecord; print "Hello!"
    Becomes:
    #!/usr/bin/perl -w use strict; require SelfRecord; print "Hello!" __END__ Hello!
    When run.

    Anima Legato
    .oO all things connect through the motion of the mind