Gossamer Forum
Home : General : Perl Programming :

grep help

Quote Reply
grep help
How can I add to this code so it searches for the '.jpeg' format also?

Code:
@blah = grep(/.gif/, readdir (BLAHDIR));

Thanks!

------------------
Jacob Wheeler
jacob@123webmaster.com
http://www.123webmaster.com
http://www.online-freebies.com
ICQ:#390147
Quote Reply
Re: grep help In reply to
Regexes are confusing, and each implementation follows slightly different rules. I believe grep expects to find a regex as the first expression, so:

'\.gif' would be more correct, since the period would match any character - such as 'mcgifford' or 'gift' -- and you want it to match '.gif'

and

(\.gif|\.jpe*g)/i

should find ".GIF" ".gif" ".jpeg" and ".JPG", as well as other combinations...

but again, this is in perl, so whether it would actually work in your situation depends on what your function allows.

I didn't try them, but my system grep chokes on the '|' character used like this for some reason.