I’m fairly new to perl but not to scripting languages. I have a file, and I’m trying to extract just one portion of each line that matches a regex. For example, given the file:
FLAG(123)
FLAG(456)
Not a flag
FLAG(789)
I’d like to extract the list [123, 456, 789]
The regex is obviously /^FLAG\((\w+)/. My question is, what’s an easy way to extract this data in perl?
It’s obviously not hard to set up a loop and do a bunch of =~ matches, but I’ve heard quite a bit about perl’s terseness and how it has an operator for everything, so I’m wondering if there’s a slick, simple way to do this.
Also, can you point me towards a good perl reference where I can find out slick ways to do other things like this when the opportunity next arises? There are many perl resources on the web, but 90% of them are too simple and the other 10% I seem to lose the signal in the noise.
Thanks!
mapis your friend here.