in reply to A spiked version of test.pl

Is there Perl code to add thoes cool line number to a file? Hmm. I guess I could stop bing lazy and create one. :)

Sparky

Replies are listed 'Best First'.
Re: Re: A spiked version of test.pl
by blakem (Monsignor) on Dec 14, 2001 at 05:25 UTC
    Beatnik's source filter - Filter::NumberLines - will number the lines *and* maintain the runability of said lines...
    #!/usr/bin/perl -w use lib './perllibs'; use Filter::NumberLines; 004: use strict; 005: 006: print "I like Jellybeans\n";
    Not only were the 004-??? line number put in there for me, but the program runs correctly just like that with the line numbers included. Very clever stuff.

    -Blake

(Ovid) Re: Re: A spiked version of test.pl
by Ovid (Cardinal) on Dec 14, 2001 at 02:31 UTC
    perl -pi.bak -e 's/^/sprintf( "%05d", $.).": "/e' test.pl

    Of course, that will make your program unuseable :) If you need to remove them again:

    perl -pi.bak -e 's/^(?:\s+)?\d+:\s//' test.pl

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.