|Just another Perl shrine|
Need help understanding code snippet with "grep -f"by fifaltra (Acolyte)
|on Dec 23, 2015 at 02:42 UTC||Need Help??|
fifaltra has asked for the wisdom of the Perl Monks concerning the following question:
Dear Perl Monks,
when I first started using perl, I had a friend kickstart me with some scripts that I needed at the time. I then went and kept modifying and rearranging those scripts to fit new problems I wanted to solve with perl. Due to this, I still often have snippets in my code that I just use as a black box, which is fine, until I want the behaviour to change slightly.
So now I have this snippet here:
My guess what this does is: The qw makes an array, which map then takes to create another array that contains the string with $_ replaced by the entries of the first array. And then grep takes this and magic happens, and I get an array of files, if there are files matching this pattern.
So, first question: Am I on the right path here?
Now, what I want to do is basically this:
But perl does not understand me, which I also did not really expect in this case. (I hope you do, but just in case, I want all files that match this pattern, just as the shell would work. I realise just now that of course grep in the shell would not work like this, so in the shell I would just grep the first and the second part separately...)
So my second and third questions are: What exactly does this grep -f do? I couldn't find any documentation on this. And how do I have to modify the line so that it finds all files in the directory archiv that match the pattern ".e$id"?
Here's more of my code for context: