Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Answer: How do I get the last occurrance of a word (or words) in a file?

by merlyn (Sage)
on May 11, 2000 at 02:13 UTC ( #11084=categorized answer: print w/replies, xml ) Need Help??

Q&A > regular expressions > How do I get the last occurrence of a word (or words) in a file? - Answer contributed by merlyn

By getting the "last" occurrance, I don't know if you want to know the line it's on (as a line number), or the contents of the line. So I'll do both:
while (<>) { if /^((VIS|JIT|MAD)HU2?):/) { $found{$1} = [$., $_]; } } for (sort keys %found) { print "$_ => @{$found{$_}}\n"; }
season to taste.

  • Comment on Answer: How do I get the last occurrance of a word (or words) in a file?
  • Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (13)
As of 2016-12-05 16:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (88 votes). Check out past polls.