How can I implement Unix grep in Perl?

Posted by Ankit Rathod on Stack Overflow See other posts from Stack Overflow or by Ankit Rathod
Published on 2010-10-03T02:51:58Z Indexed on 2010/12/26 3:54 UTC
Read the original article Hit count: 390

Filed under:
|
|

How can I implement grep of Unix in Perl? I tried to use Perl's built-in grep. Here is the code which is not working:

$pattern = @ARGV[0];
$file= @ARGV[1];

open($fp,$file);

@arr = <$fp>;

@lines = grep $pattern, @arr;

close($fp);
print @lines;

And by the way, i am trying only basic grep functionality not full featured and secondly i don't want to do string parsing myself. I want to use inbuilt grep or some function of Perl.

Thanks in advance :)

© Stack Overflow or respective owner

Related posts about regex

Related posts about perl