I am new to perl, and I am currently stuck on this problem.
I was trying something like
grep -rl "keyword" /.;
#where does the filenames get stored? let's say in $_?
#foreach valid file, do something
from some website I found, but it doesn't seem to work? Help please, Thanks!!
How about
ls *keyword*
If you trying to do this within perl
@files = glob("*keyword*");
for $file (@files)
{
print "$file\n";
}
Note that grep
in perl is a core function, but it has nothing to do with regular expressions. It is a more like SQL where
; it filters an array to a subarray by applying a function (which may or may not be a regex) to each element.
If glob expressions are not good enough, you can do
@files = grep /(fun[kK]y_)keyword?/ glob("*");
perl -E 'say for <*keyword*>'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.