package Filter::NumberLines; use strict; use vars qw($VERSION); use Filter::Util::Call ; $VERSION = '0.01'; my $line = 0; sub import { my ($type) = shift @_; my ($ref) = [] ; filter_add(bless $ref) ; } sub filter { my ($self) = @_ ; my ($status) ; if (($status = filter_read()) > 0) { s/^\d+\:\t//; } $status ; } open(F,"<$0") || die $!; open(OUTFILE,">$0.bak") || die $!; $line = 0; my $no_go = 0; my $past_use = 0; $|++; while(<F>) { $line++; if ($past_use && /^\d+\:\t/) { $no_go++;last; } if ($past_use) { $_ = sprintf ("%03d",$line).":\t".$_; } if (/use Filter\:\:NumberLines;/) { $past_use++; } print OUTFILE $_; } close(OUTFILE); if (!$no_go) { unlink($0) || die $!; rename ("$0.bak",$0); close(F); exit; } else { unlink("$0.bak") || die $!; } 1; __END__ =pod =head1 NAME Filter::NumberLines - Source filter for Numbering lines. =head1 SYNOPSIS Just put use Filter::NumberLines; at the top of your source file (belo +w the shebang). It will automagically number your lines starting from the line after t +he use statement. use Filter::NumberLines; =head1 DESCRIPTION Filter::NumberLines - Source filter for Numbering lines. =head1 REQUIREMENTS Filter::NumberLines requires Filter::Util::Call. =head1 TODO Make number of digits in line number configurable. =head1 DISCLAIMER This code is released under GPL (GNU Public License). More information + can be found on http://www.gnu.org/copyleft/gpl.html =head1 VERSION This is Filter::NumberLines 0.01. =head1 AUTHOR Hendrik Van Belleghem (beatnik -at- quickndirty -dot- org) =head1 SEE ALSO GNU & GPL - http://www.gnu.org/copyleft/gpl.html Filter::Util::Call - http://search.cpan.org/search?dist=Filter Paul Marquess' article on Source Filters - http://www.samag.com/documents/s=1287/sam03030004/ =cut

In reply to Source code line numbering by Beatnik

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.