Thanks for the link Mike. One of my favourites is $. although I haven't managed to use it much yet. $. Is not a regex variable but here is an example of using it to identify the line numbers where a regex match succeeds.
#!/usr/bin/perl
use strict;
use warnings;
while (<DATA>){
if (m/\bcane\b/){
#The following statement uses the special variable $.
#which contains the current line number of the input file
print "Line number $. of the file contains the word $&.\n";
}
}
__DATA__
The Spring blew trumpets of color;
Her Green sang in my brain --
I heard a blind man groping
"Tap -- tap" with his cane;
I pitied him in his blindness;
But can I boast, "I see"?
Perhaps there walks a spirit
Close by, who pities me, --
A spirit who hears me tapping
The five-sensed cane of mind
Amid such unguessed glories --
That I am worse than blind.
This prints the following:
Line number 4 of the file contains the word cane.
Line number 12 of the file contains the word cane. d5e5
Practically a Posting Shark
810 posts since Sep 2009
Reputation Points: 159
Solved Threads: 159