in reply to $. - smarter than you might think

I love $., specially because it works so well with the scalar form of the .. operator. For example, to extract the subroutines of a script and label the lines with linenumbers one could use this:
$ cat test2.pl #!/usr/bin/perl my $god; sub test { my ($param) = @_; print $param; return } __END__ $ cat test.pl | perl -ne 'print "$. $_" if /^sub/ .. /[}]/' 5 sub test { 6 my ($param) = @_; 7 print $param; 8 return 9 }

Replies are listed 'Best First'.
Re^2: $. - smarter than you might think
by GrandFather (Saint) on Jun 28, 2006 at 20:24 UTC

    so long as there are no blocks, quoted strings or regexen containing } in the sub. A pretty unusual sib. :)

    But, especially after I found out about how 'smart' $. is, I agree about it's potential usefulness.


    DWIM is Perl's answer to Gödel